Class: Apify::Action
- Inherits:
-
Object
- Object
- Apify::Action
- Defined in:
- lib/apify/action.rb
Instance Attribute Summary collapse
-
#description(description = nil, &block) ⇒ Object
readonly
Returns the value of attribute description.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #example(schema_nature) ⇒ Object
-
#initialize(method, name, &block) ⇒ Action
constructor
A new instance of Action.
- #respond(args = nil, &block) ⇒ Object
- #responder ⇒ Object
- #returns_value? ⇒ Boolean
- #schema(nature, &block) ⇒ Object
- #takes_args? ⇒ Boolean
- #uid ⇒ Object
Constructor Details
#initialize(method, name, &block) ⇒ Action
Returns a new instance of Action.
6 7 8 9 10 11 |
# File 'lib/apify/action.rb', line 6 def initialize(method, name, &block) @method = method @name = name @schemas = Hash.new({}.freeze) instance_eval(&block) end |
Instance Attribute Details
#description(description = nil, &block) ⇒ Object (readonly)
Returns the value of attribute description.
4 5 6 |
# File 'lib/apify/action.rb', line 4 def description @description end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
4 5 6 |
# File 'lib/apify/action.rb', line 4 def method @method end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/apify/action.rb', line 4 def name @name end |
Instance Method Details
#example(schema_nature) ⇒ Object
52 53 54 |
# File 'lib/apify/action.rb', line 52 def example(schema_nature) example_for_schema(schema(schema_nature)) end |
#respond(args = nil, &block) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/apify/action.rb', line 22 def respond(args = nil, &block) if block @responder = block else Apify::Exchange.new.tap do |exchange| exchange.respond(args, self) end end end |
#responder ⇒ Object
48 49 50 |
# File 'lib/apify/action.rb', line 48 def responder @responder || lambda {} end |
#returns_value? ⇒ Boolean
44 45 46 |
# File 'lib/apify/action.rb', line 44 def returns_value? schema(:value) != {} end |
#schema(nature, &block) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/apify/action.rb', line 13 def schema(nature, &block) nature = nature.to_sym if block @schemas[nature] = eval_schema(block) else @schemas[nature] end end |
#takes_args? ⇒ Boolean
40 41 42 |
# File 'lib/apify/action.rb', line 40 def takes_args? schema(:args) != {} end |
#uid ⇒ Object
56 57 58 |
# File 'lib/apify/action.rb', line 56 def uid "#{method}_#{name}" end |