Class: Taskable::Task

Inherits:
Object show all
Defined in:
lib/ratch/task.rb,
lib/ratch/task2.rb

Overview

Task Class

Direct Known Subclasses

FileTask

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#baseObject (readonly)

Returns the value of attribute base.



55
56
57
# File 'lib/ratch/task.rb', line 55

def base
  @base
end

#descriptionObject (readonly)

Returns the value of attribute description.



59
60
61
# File 'lib/ratch/task.rb', line 59

def description
  @description
end

#functionObject (readonly)

Returns the value of attribute function.



58
59
60
# File 'lib/ratch/task.rb', line 58

def function
  @function
end

#requisiteObject (readonly)

Returns the value of attribute requisite.



57
58
59
# File 'lib/ratch/task.rb', line 57

def requisite
  @requisite
end

#targetObject (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

#prerequisiteObject



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