Class: Carbide::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/carbide/task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#actionsObject (readonly)

Returns the value of attribute actions.



3
4
5
# File 'lib/carbide/task.rb', line 3

def actions
  @actions
end

#managerObject (readonly)

Returns the value of attribute manager.



3
4
5
# File 'lib/carbide/task.rb', line 3

def manager
  @manager
end

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

#clearObject



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_actionsObject



65
66
67
68
# File 'lib/carbide/task.rb', line 65

def clear_actions
  actions.clear
  self
end

#clear_post_tasksObject



75
76
77
78
# File 'lib/carbide/task.rb', line 75

def clear_post_tasks
  post_tasks.clear
  self
end

#clear_pre_tasksObject



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