Class: Taskable::Task
Overview
Task Class
Direct Known Subclasses
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#function ⇒ Object
readonly
Returns the value of attribute function.
-
#requisite ⇒ Object
readonly
Returns the value of attribute requisite.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Class Method Summary collapse
Instance Method Summary collapse
- #call(object) ⇒ Object
-
#initialize(base, target, description = nil, requisite = nil, &function) ⇒ Task
constructor
A new instance of Task.
- #prerequisite ⇒ Object
-
#rule_dag(cache = []) ⇒ Object
Collect task dependencies for running.
-
#run(object) ⇒ Object
invoke target.
- #update(requisite, &function) ⇒ Object
Constructor Details
#initialize(base, target, description = nil, requisite = nil, &function) ⇒ Task
Returns a new instance of Task.
61 62 63 64 65 66 67 |
# File 'lib/ratch/task.rb', line 61 def initialize(base, target, description=nil, requisite=nil, &function) @base = base @target = target.to_sym @description = description @requisite = requisite || [] @function = function end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
55 56 57 |
# File 'lib/ratch/task.rb', line 55 def base @base end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
59 60 61 |
# File 'lib/ratch/task.rb', line 59 def description @description end |
#function ⇒ Object (readonly)
Returns the value of attribute function.
58 59 60 |
# File 'lib/ratch/task.rb', line 58 def function @function end |
#requisite ⇒ Object (readonly)
Returns the value of attribute requisite.
57 58 59 |
# File 'lib/ratch/task.rb', line 57 def requisite @requisite end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
56 57 58 |
# File 'lib/ratch/task.rb', line 56 def target @target end |
Class Method Details
.parse_arguments(name_and_reqs, &action) ⇒ Object
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/ratch/task.rb', line 108 def self.parse_arguments(name_and_reqs, &action) if Hash===name_and_reqs target = name_and_reqs.keys.first.to_s reqs = [name_and_reqs.values.first].flatten else target = name_and_reqs.to_s reqs = [] end return target, reqs, action end |
Instance Method Details
#call(object) ⇒ Object
140 141 142 |
# File 'lib/ratch/task2.rb', line 140 def call(object) object.instance_eval(&function) end |
#prerequisite ⇒ Object
76 77 78 79 80 |
# File 'lib/ratch/task.rb', line 76 def prerequisite base.ancestors.select{|a| a < Taskable}.collect{ |a| a.tasks[target].requisite }.flatten.uniq end |
#rule_dag(cache = []) ⇒ Object
Collect task dependencies for running.
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/ratch/task.rb', line 96 def rule_dag(cache=[]) prerequisite.each do |r| next if cache.include?(r) t = base.tasks[r] t.rule_dag(cache) #cache << dep end cache << target.to_s cache end |
#run(object) ⇒ Object
invoke target
83 84 85 86 87 88 |
# File 'lib/ratch/task.rb', line 83 def run(object) rd = rule_dag rd.each do |t| object.send("#{t}:task") end end |
#update(requisite, &function) ⇒ Object
70 71 72 73 |
# File 'lib/ratch/task.rb', line 70 def update(requisite, &function) @requisite.concat(requisite).uniq! @function = function if function end |