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

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 71
def initialize(task_name)
  @name = task_name
  @prerequisites = []
  @actions = []
end
            

Public Instance 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 141
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 127
def clear
  TASKS.clear
  RULES.clear
end
            
create_rule(args, &block) click to toggle source

Define a rule for synthesizing tasks.

 
               # File minirake, line 164
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 158
def define_task(args, &block)
  task_name, deps = resolve_args(args)
  lookup(task_name).enhance([deps].flatten, &block)
end
            
enhance(deps=nil, &block) click to toggle source

Enhance a task with prerequisites or actions. Returns self.

 
               # File minirake, line 78
def enhance(deps=nil, &block)
  @prerequisites |= deps if deps
  @actions << block if block_given?
  self
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 182
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
            
execute() click to toggle source

Execute the actions associated with this task.

 
               # File minirake, line 100
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
end
            
invoke() click to toggle source

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

 
               # File minirake, line 90
def invoke
  puts "Invoke #{name} (already=[#{@already_invoked}], needed=[#{needed?}])" if $trace
  return if @already_invoked
  @already_invoked = true
  prerequisites = @prerequisites.collect{ |n| n.is_a?(Proc) ? n.call(name) : n }.flatten
  prerequisites.each { |n| Task[n].invoke }
  execute if needed?
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 173
def lookup(task_name)
  name = task_name.to_s
  TASKS[name] ||= self.new(name)
end
            
name() click to toggle source

Name of the task.

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

Is this task needed?

 
               # File minirake, line 109
def needed?
  true
end
            
tasks() click to toggle source

List of all defined tasks.

 
               # File minirake, line 133
def tasks
  TASKS.keys.sort.collect { |tn| Task[tn] }
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 115
def timestamp
  prerequisites = @prerequisites.collect{ |n| n.is_a?(Proc) ? n.call(name) : n }.flatten
  prerequisites.collect { |n| Task[n].timestamp }.max || Time.now
end
            

Private Instance Methods

resolve_args(args) click to toggle source

Resolve the arguments for a task/rule.

 
               # File minirake, line 208
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
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.

blog comments powered by Disqus