Class: BehaveFun::Task
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#as_json, #dump_status, #name, #restore_status, #serializable_status_fields
Constructor Details
#initialize(params = {}) ⇒ Task
Returns a new instance of Task.
8
9
10
11
12
|
# File 'lib/behave_fun/task.rb', line 8
def initialize(params = {})
self.params = params
@children = []
@status = :fresh
end
|
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
6
7
8
|
# File 'lib/behave_fun/task.rb', line 6
def children
@children
end
|
#context ⇒ Object
Returns the value of attribute context.
6
7
8
|
# File 'lib/behave_fun/task.rb', line 6
def context
@context
end
|
#control ⇒ Object
Returns the value of attribute control.
5
6
7
|
# File 'lib/behave_fun/task.rb', line 5
def control
@control
end
|
#guard ⇒ Object
Returns the value of attribute guard.
5
6
7
|
# File 'lib/behave_fun/task.rb', line 5
def guard
@guard
end
|
#params ⇒ Object
Returns the value of attribute params.
5
6
7
|
# File 'lib/behave_fun/task.rb', line 5
def params
@params
end
|
#status ⇒ Object
Returns the value of attribute status.
6
7
8
|
# File 'lib/behave_fun/task.rb', line 6
def status
@status
end
|
Class Method Details
.task_name ⇒ Object
14
15
16
|
# File 'lib/behave_fun/task.rb', line 14
def self.task_name
name.demodulize.underscore
end
|
Instance Method Details
#add_child(task) ⇒ Object
92
93
94
95
|
# File 'lib/behave_fun/task.rb', line 92
def add_child(task)
@children << task
task.control = self
end
|
#cancel ⇒ Object
38
39
40
41
|
# File 'lib/behave_fun/task.rb', line 38
def cancel
@status = :cancelled
children.each { |child| child.cancel }
end
|
#cancelled? ⇒ Boolean
59
60
61
|
# File 'lib/behave_fun/task.rb', line 59
def cancelled?
@status == :cancelled
end
|
#child_fail ⇒ Object
88
|
# File 'lib/behave_fun/task.rb', line 88
def child_fail; end
|
#child_running ⇒ Object
90
|
# File 'lib/behave_fun/task.rb', line 90
def child_running; end
|
#child_success ⇒ Object
86
|
# File 'lib/behave_fun/task.rb', line 86
def child_success; end
|
#dup ⇒ Object
119
120
121
122
123
|
# File 'lib/behave_fun/task.rb', line 119
def dup
cloned = self.class.new(params)
children.each { cloned.add_child(_1.dup) }
cloned
end
|
#ended? ⇒ Boolean
63
64
65
|
# File 'lib/behave_fun/task.rb', line 63
def ended?
succeeded? || failed? || cancelled?
end
|
#execute ⇒ Object
84
|
# File 'lib/behave_fun/task.rb', line 84
def execute; end
|
#fail ⇒ Object
33
34
35
36
|
# File 'lib/behave_fun/task.rb', line 33
def fail
@status = :failed
control.child_fail if control
end
|
#failed? ⇒ Boolean
55
56
57
|
# File 'lib/behave_fun/task.rb', line 55
def failed?
@status == :failed
end
|
#fresh? ⇒ Boolean
43
44
45
|
# File 'lib/behave_fun/task.rb', line 43
def fresh?
@status == :fresh
end
|
#guard_passed? ⇒ Boolean
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/behave_fun/task.rb', line 67
def guard_passed?
return true unless guard
guard.context = context
guard.reset
guard.run
case guard.status
when :succeeded then true
when :failed then false
else
raise Error, 'Guard should finish in one step'
end
end
|
#reset ⇒ Object
113
114
115
116
117
|
# File 'lib/behave_fun/task.rb', line 113
def reset
cancel
@status = :fresh
children.each { |child| child.reset }
end
|
#run ⇒ Object
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/behave_fun/task.rb', line 97
def run
raise Error, 'Cannot run ended task' if ended?
if fresh?
if guard_passed?
start
running
execute
else
fail
end
else
running
execute
end
end
|
#running ⇒ Object
23
24
25
26
|
# File 'lib/behave_fun/task.rb', line 23
def running
@status = :running
control.child_running if control
end
|
#running? ⇒ Boolean
47
48
49
|
# File 'lib/behave_fun/task.rb', line 47
def running?
@status == :running
end
|
#start ⇒ Object
82
|
# File 'lib/behave_fun/task.rb', line 82
def start; end
|
#succeeded? ⇒ Boolean
51
52
53
|
# File 'lib/behave_fun/task.rb', line 51
def succeeded?
@status == :succeeded
end
|
#success ⇒ Object
28
29
30
31
|
# File 'lib/behave_fun/task.rb', line 28
def success
@status = :succeeded
control.child_success if control
end
|