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
50 51 52 |
# File 'lib/apify/action.rb', line 50 def example(schema_nature) example_for_schema(schema(schema_nature)) end |
#respond(args = nil, &block) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/apify/action.rb', line 22 def respond(args = nil, &block) if block @responder = block else Apify::Exchange.new.respond(args, self) end end |
#responder ⇒ Object
46 47 48 |
# File 'lib/apify/action.rb', line 46 def responder @responder || lambda {} end |
#returns_value? ⇒ Boolean
42 43 44 |
# File 'lib/apify/action.rb', line 42 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
38 39 40 |
# File 'lib/apify/action.rb', line 38 def takes_args? schema(:args) != {} end |
#uid ⇒ Object
54 55 56 |
# File 'lib/apify/action.rb', line 54 def uid "#{method}_#{name}" end |