Module: Taskable::ObjectDSL

Defined in:
lib/ratch/task2.rb

Instance Method Summary collapse

Instance Method Details

#desc(description) ⇒ Object

Set a description to be used by then next defined task in this class.



73
74
75
# File 'lib/ratch/task2.rb', line 73

def desc(description)
  @desc = description
end

#task(target_and_requisite, &function) ⇒ Object

Define a task.



78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/ratch/task2.rb', line 78

def task(target_and_requisite, &function)
  target, requisite, function = *Task.parse_arguments(target_and_requisite, &function)
  task = tasks[target.to_sym] ||= (
    tdesc = @desc
    @desc = nil
    Task.new(self, target, tdesc) #, reqs, actions)
  )
  task.update(requisite, &function)

  define_method("#{target}Trigger"){ task.run(self) }
  define_method("#{target}:task", &function)
end

#tasks(target = nil) ⇒ Object

Without an argument, returns list of tasks defined for this class.

If a task’s target name is given, will return the first task mathing the name found in the class’ inheritance chain. This is important ot ensure task are inherited in the same manner that methods are.



61
62
63
64
65
66
67
68
69
70
# File 'lib/ratch/task2.rb', line 61

def tasks(target=nil)
  if target
    target = target.to_sym
    anc = ancestors.select{|a| a < DSL}
    t = nil; anc.find{|a| t = a.tasks[target]}
    return t
  else
    @tasks ||= {}
  end
end