Class: FunctionsFramework::Function
- Inherits:
-
Object
- Object
- FunctionsFramework::Function
- Defined in:
- lib/functions_framework/function.rb
Overview
Representation of a function.
A function has a name, a type, and a code definition.
Instance Attribute Summary collapse
-
#block ⇒ Proc
readonly
The function code as a proc.
-
#name ⇒ String
readonly
The function name.
-
#type ⇒ Symbol
readonly
The function type.
Instance Method Summary collapse
-
#call(argument) ⇒ Object
Call the function.
-
#initialize(name, type, &block) ⇒ Function
constructor
Create a new function definition.
Constructor Details
#initialize(name, type, &block) ⇒ Function
Create a new function definition.
30 31 32 33 34 |
# File 'lib/functions_framework/function.rb', line 30 def initialize name, type, &block @name = name @type = type @block = block end |
Instance Attribute Details
#block ⇒ Proc (readonly)
Returns The function code as a proc.
49 50 51 |
# File 'lib/functions_framework/function.rb', line 49 def block @block end |
#name ⇒ String (readonly)
Returns The function name.
39 40 41 |
# File 'lib/functions_framework/function.rb', line 39 def name @name end |
#type ⇒ Symbol (readonly)
Returns The function type.
44 45 46 |
# File 'lib/functions_framework/function.rb', line 44 def type @type end |
Instance Method Details
#call(argument) ⇒ Object
Call the function. You must pass an argument appropriate to the type of function.
- A
:httptype function takes aRack::Requestargument, and returns a Rack response type. See Registry.add_http. - A
:cloud_eventtype function takes a CloudEvents::Event argument, and does not return a value. See Registry.add_cloud_event.
64 65 66 67 68 69 70 71 |
# File 'lib/functions_framework/function.rb', line 64 def call argument case type when :event block.call argument.data, argument else block.call argument end end |