Class: Carbide::Task
- Inherits:
-
Object
- Object
- Carbide::Task
- Defined in:
- lib/carbide/task.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#manager ⇒ Object
readonly
Returns the value of attribute manager.
-
#name ⇒ Object
(also: #to_sym)
readonly
Returns the value of attribute name.
-
#post_tasks ⇒ Object
readonly
Returns the value of attribute post_tasks.
-
#pre_tasks ⇒ Object
readonly
Returns the value of attribute pre_tasks.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #append(tasks) ⇒ Object
- #clear ⇒ Object
- #clear_actions ⇒ Object
- #clear_post_tasks ⇒ Object
- #clear_pre_tasks ⇒ Object
- #enhance(action) ⇒ Object
- #execute(*args) ⇒ Object
-
#initialize(manager, name) ⇒ Task
constructor
A new instance of Task.
- #invoke(*args) ⇒ Object
- #invoke_post_tasks(*args) ⇒ Object
- #invoke_pre_tasks(*args) ⇒ Object
- #prepend(tasks) ⇒ Object
Constructor Details
#initialize(manager, name) ⇒ Task
Returns a new instance of Task.
5 6 7 8 9 10 11 |
# File 'lib/carbide/task.rb', line 5 def initialize(manager, name) @manager = manager @name = name.to_sym @actions = [] @pre_tasks = [] @post_tasks = [] end |
Instance Attribute Details
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
3 4 5 |
# File 'lib/carbide/task.rb', line 3 def actions @actions end |
#manager ⇒ Object (readonly)
Returns the value of attribute manager.
3 4 5 |
# File 'lib/carbide/task.rb', line 3 def manager @manager end |
#name ⇒ Object (readonly) Also known as: to_sym
Returns the value of attribute name.
3 4 5 |
# File 'lib/carbide/task.rb', line 3 def name @name end |
#post_tasks ⇒ Object (readonly)
Returns the value of attribute post_tasks.
3 4 5 |
# File 'lib/carbide/task.rb', line 3 def post_tasks @post_tasks end |
#pre_tasks ⇒ Object (readonly)
Returns the value of attribute pre_tasks.
3 4 5 |
# File 'lib/carbide/task.rb', line 3 def pre_tasks @pre_tasks end |
Instance Method Details
#==(other) ⇒ Object
15 16 17 18 |
# File 'lib/carbide/task.rb', line 15 def ==(other) self.class === other && name == other.name end |
#append(tasks) ⇒ Object
30 31 32 33 |
# File 'lib/carbide/task.rb', line 30 def append(tasks) @post_tasks |= Array(tasks).map(&:name) self end |
#clear ⇒ Object
80 81 82 83 84 85 |
# File 'lib/carbide/task.rb', line 80 def clear clear_actions clear_pre_tasks clear_post_tasks self end |
#clear_actions ⇒ Object
65 66 67 68 |
# File 'lib/carbide/task.rb', line 65 def clear_actions actions.clear self end |
#clear_post_tasks ⇒ Object
75 76 77 78 |
# File 'lib/carbide/task.rb', line 75 def clear_post_tasks post_tasks.clear self end |
#clear_pre_tasks ⇒ Object
70 71 72 73 |
# File 'lib/carbide/task.rb', line 70 def clear_pre_tasks pre_tasks.clear self end |
#enhance(action) ⇒ Object
20 21 22 23 |
# File 'lib/carbide/task.rb', line 20 def enhance(action) actions << action self end |
#execute(*args) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/carbide/task.rb', line 35 def execute(*args) actions.each do |action| action.execute(*args) end self end |
#invoke(*args) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/carbide/task.rb', line 42 def invoke(*args) invoke_pre_tasks(*args) execute(*args) invoke_post_tasks(*args) self end |
#invoke_post_tasks(*args) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/carbide/task.rb', line 57 def invoke_post_tasks(*args) post_tasks.each do |post_task| task = manager[post_task] task.invoke(*args) end self end |
#invoke_pre_tasks(*args) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/carbide/task.rb', line 49 def invoke_pre_tasks(*args) pre_tasks.each do |pre_task| task = manager[pre_task] task.invoke(*args) end self end |
#prepend(tasks) ⇒ Object
25 26 27 28 |
# File 'lib/carbide/task.rb', line 25 def prepend(tasks) @pre_tasks |= Array(tasks).map(&:name) self end |