In Files

  • minirake

MiniRake::Task

Constants

RULES
TASKS

Attributes

prerequisites[R]

List of prerequisites for a task.

source[RW]

Source dependency for rule synthesized tasks. Nil if task was not sythesized from a rule.

Public Class Methods

[](task_name) click to toggle source

Return a task with the given name. If the task is not currently known, try to synthesize one from the defined rules. If no rules are found, but an existing file matches the task name, assume it is a file task with no dependencies or actions.

 
               # File minirake, line 168
def [](task_name)
  task_name = task_name.to_s
  if task = TASKS[task_name]
    return task
  end
  if task = enhance_with_matching_rule(task_name)
    return task
  end
  if File.exist?(task_name)
    return FileTask.define_task(task_name)
  end
  fail "Don't know how to rake #{task_name}"
end
            
clear() click to toggle source

Clear the task list. This cause rake to immediately forget all the tasks that have been assigned. (Normally used in the unit tests.)

 
               # File minirake, line 154
def clear
  TASKS.clear
  RULES.clear
end
            
create_rule(args, &block) click to toggle source

Define a rule for synthesizing tasks.

 
               # File minirake, line 191
def create_rule(args, &block)
  pattern, deps = resolve_args(args)
  pattern = Regexp.new(Regexp.quote(pattern) + '$') if String === pattern
  RULES << [pattern, deps, block]
end
            
define_task(args, &block) click to toggle source

Define a task given args and an option block. If a rule with the given name already exists, the prerequisites and actions are added to the existing task.

 
               # File minirake, line 185
def define_task(args, &block)
  task_name, deps = resolve_args(args)
  lookup(task_name).enhance([deps].flatten, &block)
end
            
enhance_with_matching_rule(task_name) click to toggle source

If a rule can be found that matches the task name, enhance the task with the prerequisites and actions from the rule. Set the source attribute of the task appropriately for the rule. Return the enhanced task or nil of no rule was found.

 
               # File minirake, line 209
def enhance_with_matching_rule(task_name)
  RULES.each do |pattern, extensions, block|
    if pattern.match(task_name)
      ext = extensions.first
      deps = extensions[1..-1]
      case ext
      when String
        source = task_name.sub(/\.[^.]*$/, ext)
      when Proc
        source = ext.call(task_name)
      else
        fail "Don't know how to handle rule dependent: #{ext.inspect}"
      end
      if File.exist?(source)
        task = FileTask.define_task({task_name => [source]+deps}, &block)
        task.source = source
        return task
      end
    end
  end
  nil
end
            
lookup(task_name) click to toggle source

Lookup a task. Return an existing task if found, otherwise create a task of the current type.

 
               # File minirake, line 200
def lookup(task_name)
  name = task_name.to_s
  TASKS[name] ||= self.new(name)
end
            
new(task_name) click to toggle source

Create a task named task_name with no actions or prerequisites.. use enhance to add actions and prerequisites.

 
               # File minirake, line 75
def initialize(task_name)
  @name = task_name
  @prerequisites = []
  @actions = []
end
            
tasks() click to toggle source

List of all defined tasks.

 
               # File minirake, line 160
def tasks
  TASKS.keys.sort.collect { |tn| Task[tn] }
end
            

Private Class Methods

resolve_args(args) click to toggle source

Resolve the arguments for a task/rule.

 
               # File minirake, line 235
def resolve_args(args)
  case args
  when Hash
    fail "Too Many Task Names: #{args.keys.join(' ')}" if args.size > 1
    fail "No Task Name Given" if args.size < 1
    task_name = args.keys[0]
    deps = args[task_name]
    deps = [deps] if (String===deps) || (Regexp===deps) || (Proc===deps)
  else
    task_name = args
    deps = []
  end
  [task_name, deps]
end
            

Public Instance Methods

done?() click to toggle source
 
               # File minirake, line 93
def done?; @done end
            
enhance(deps=nil, &block) click to toggle source

Enhance a task with prerequisites or actions. Returns self.

 
               # File minirake, line 82
def enhance(deps=nil, &block)
  @prerequisites |= deps if deps
  @actions << block if block_given?
  self
end
            
execute() click to toggle source

Execute the actions associated with this task.

 
               # File minirake, line 126
def execute
  puts "Execute #{name}" if $trace
  self.class.enhance_with_matching_rule(name) if @actions.empty?
  unless $dryrun
    @actions.each { |act| act.call(self) }
  end
  @done = true
  @running = false
end
            
invoke() click to toggle source

Invoke the task if it is needed. Prerequisites are invoked first.

 
               # File minirake, line 97
def invoke
  puts "Invoke #{name} (already=[#{@already_invoked}], needed=[#{needed?}])" if $trace
  return if @already_invoked
  prerequisites = @prerequisites.collect{ |n| n.is_a?(Proc) ? n.call(name) : n }.flatten
  prerequisites.each do |n|
    t = Task[n]
    unless t.done?
      return prerequisites.select{|v| v = Task[v]; v && (!v.done? || !v.running?) }
    end
  end

  @already_invoked = true

  if needed?
    @running = true
    if $rake_root_fiber
      return Fiber.new do
        self.execute
        $rake_root_fiber.transfer
      end
    else
      self.execute
    end
  end

  @done = true
end
            
name() click to toggle source

Name of the task.

 
               # File minirake, line 89
def name
  @name.to_s
end
            
needed?() click to toggle source

Is this task needed?

 
               # File minirake, line 137
def needed?
  true
end
            
running?() click to toggle source
 
               # File minirake, line 94
def running?; @running end
            
timestamp() click to toggle source

Timestamp for this task. Basic tasks return the current time for their time stamp. Other tasks can be more sophisticated.

 
               # File minirake, line 143
def timestamp
  Time.now
end