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
-
#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 35 36 |
# File 'lib/functions_framework/function.rb', line 30 def initialize name, type, &block @name = name @type = type @execution_context_class = Class.new do define_method :call, &block end end |
Instance Attribute Details
#name ⇒ String (readonly)
Returns The function name.
41 42 43 |
# File 'lib/functions_framework/function.rb', line 41 def name @name end |
#type ⇒ Symbol (readonly)
Returns The function type.
46 47 48 |
# File 'lib/functions_framework/function.rb', line 46 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.
61 62 63 64 65 66 67 68 69 |
# File 'lib/functions_framework/function.rb', line 61 def call argument execution_context = @execution_context_class.new case type when :event execution_context.call argument.data, argument else execution_context.call argument end end |