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) ⇒ Object
Set a global.
Constructor Details
#initialize(globals: nil, logger: nil) ⇒ Callable
Create a callable object with the given context.
179 180 181 182 |
# File 'lib/functions_framework/function.rb', line 179 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:http
or:cloud_event
.
You can also set additional globals from a startup task.
198 199 200 |
# File 'lib/functions_framework/function.rb', line 198 def global key @__globals[key] end |
#logger ⇒ Logger
A logger for use by this call.
219 220 221 |
# File 'lib/functions_framework/function.rb', line 219 def logger @__logger end |
#set_global(key, value) ⇒ Object
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.
210 211 212 |
# File 'lib/functions_framework/function.rb', line 210 def set_global key, value @__globals[key] = value end |