Class: Elevate::TaskDefinition
- Inherits:
-
Object
- Object
- Elevate::TaskDefinition
show all
- Defined in:
- lib/elevate/task_definition.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name, options, &block) ⇒ TaskDefinition
Returns a new instance of TaskDefinition.
3
4
5
6
7
8
9
|
# File 'lib/elevate/task_definition.rb', line 3
def initialize(name, options, &block)
@name = name
@options = options
@handlers = {}
instance_eval(&block)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/elevate/task_definition.rb', line 15
def method_missing(method, *args, &block)
if method.to_s.start_with?("on_")
raise ArgumentError, "wrong number of arguments" unless args.empty?
raise ArgumentError, "block not supplied" unless block_given?
@handlers[method.to_sym] = block
else
super
end
end
|
Instance Attribute Details
#handlers ⇒ Object
Returns the value of attribute handlers.
12
13
14
|
# File 'lib/elevate/task_definition.rb', line 12
def handlers
@handlers
end
|
#name ⇒ Object
Returns the value of attribute name.
11
12
13
|
# File 'lib/elevate/task_definition.rb', line 11
def name
@name
end
|
#options ⇒ Object
Returns the value of attribute options.
13
14
15
|
# File 'lib/elevate/task_definition.rb', line 13
def options
@options
end
|
Instance Method Details
#background(&block) ⇒ Object
30
31
32
|
# File 'lib/elevate/task_definition.rb', line 30
def background(&block)
@handlers[:background] = block
end
|
#on_error(&block) ⇒ Object
34
35
36
37
38
|
# File 'lib/elevate/task_definition.rb', line 34
def on_error(&block)
raise "on_error blocks must accept one parameter" unless block.arity == 1
@handlers[:on_error] = block
end
|
#on_finish(&block) ⇒ Object
40
41
42
43
44
|
# File 'lib/elevate/task_definition.rb', line 40
def on_finish(&block)
raise "on_finish blocks must accept two parameters" unless block.arity == 2
@handlers[:on_finish] = block
end
|
#on_start(&block) ⇒ Object
46
47
48
49
50
|
# File 'lib/elevate/task_definition.rb', line 46
def on_start(&block)
raise "on_start blocks must accept zero parameters" unless block.arity == 0
@handlers[:on_start] = block
end
|
#on_update(&block) ⇒ Object
52
53
54
|
# File 'lib/elevate/task_definition.rb', line 52
def on_update(&block)
@handlers[:on_update] = block
end
|
#respond_to_missing?(method, include_private = false) ⇒ Boolean
26
27
28
|
# File 'lib/elevate/task_definition.rb', line 26
def respond_to_missing?(method, include_private = false)
method.to_s.start_with?("on_") || super
end
|
#timeout(seconds) ⇒ Object
56
57
58
59
60
|
# File 'lib/elevate/task_definition.rb', line 56
def timeout(seconds)
raise "timeout argument must be a number" unless seconds.is_a?(Numeric)
@options[:timeout_interval] = seconds
end
|