Class: Apify::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/apify/action.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#methodObject (readonly)

Returns the value of attribute method.



4
5
6
# File 'lib/apify/action.rb', line 4

def method
  @method
end

#nameObject (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

#responderObject



46
47
48
# File 'lib/apify/action.rb', line 46

def responder
  @responder || lambda {}
end

#returns_value?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


38
39
40
# File 'lib/apify/action.rb', line 38

def takes_args?
  schema(:args) != {}
end

#uidObject



54
55
56
# File 'lib/apify/action.rb', line 54

def uid
  "#{method}_#{name}"
end