Class: FunctionsFramework::Function::Callable
- Inherits:
- 
      Object
      
        - Object
- FunctionsFramework::Function::Callable
 
- Defined in:
- lib/functions_framework/function.rb
Overview
A base class for a callable object that provides calling context.
An object of this class is self while a function block is running.
Instance Method Summary collapse
- 
  
    
      #global(key)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Get the given named global. 
- 
  
    
      #initialize(globals: nil, logger: nil)  ⇒ Callable 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    Create a callable object with the given context. 
- 
  
    
      #logger  ⇒ Logger 
    
    
  
  
  
  
  
  
  
  
  
    A logger for use by this call. 
- 
  
    
      #set_global(key, value = nil, &block)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Set a global. 
Constructor Details
#initialize(globals: nil, logger: nil) ⇒ Callable
Create a callable object with the given context.
| 224 225 226 227 | # File 'lib/functions_framework/function.rb', line 224 def initialize globals: nil, logger: nil @__globals = globals || {} @__logger = logger || FunctionsFramework.logger end | 
Instance Method Details
#global(key) ⇒ Object
Get the given named global.
For most function calls, the following globals will be defined:
-  :function_name (String) The name of the running function.
-  :function_type (Symbol) The type of the running function, either:httpor:cloud_event.
You can also set additional globals from a startup task.
| 243 244 245 246 247 | # File 'lib/functions_framework/function.rb', line 243 def global key value = @__globals[key] value = value.value if LazyGlobal === value value end | 
#logger ⇒ Logger
A logger for use by this call.
| 290 291 292 | # File 'lib/functions_framework/function.rb', line 290 def logger @__logger end | 
#set_global(key, value) ⇒ self #set_global(key, &block) ⇒ self
Set a global. This can be called from startup tasks, but the globals are frozen when the server starts, so this call will raise an exception if called from a normal function.
You can set a global to a final value, or you can provide a block that lazily computes the global the first time it is requested.
| 280 281 282 283 | # File 'lib/functions_framework/function.rb', line 280 def set_global key, value = nil, &block @__globals[key] = block ? LazyGlobal.new(block) : value self end |