class Fudge::Tasks::CompositeTask

Allow for tasks to be combined

Attributes

description[RW]

Public Instance Methods

run(options={}) click to toggle source

Runs the task (by default running all other tasks in order)

# File lib/fudge/tasks/composite_task.rb, line 15
def run(options={})
  formatter = get_formatter(options)
  tasks.each do |t|
    apply_directory_settings(t)
    output_message(t, formatter)
    return unless t.run(options)
  end
end
tasks() click to toggle source

Define task array

# File lib/fudge/tasks/composite_task.rb, line 10
def tasks
  @tasks ||= []
end

Private Instance Methods

apply_directory_settings(task) click to toggle source

load fudge settings for the specified task, by name

# File lib/fudge/tasks/composite_task.rb, line 27
def apply_directory_settings(task)
  task.options.merge!(task_options(task.class.name.to_s)) if defined? task.options
end
args_s(t) click to toggle source
# File lib/fudge/tasks/composite_task.rb, line 56
def args_s(t)
  t.respond_to?(:args) && t.args ? t.args.join(', ') : ''
end
fudge_settings() click to toggle source

load fudge settings for the current directory

# File lib/fudge/tasks/composite_task.rb, line 44
def fudge_settings
  fpath = "#{Dir.pwd}/fudge_settings.yml"
  if File.exist?(fpath)
    return ::YAML.load_file(fpath)
  end
  {}
end
output_message(t, formatter) click to toggle source
# File lib/fudge/tasks/composite_task.rb, line 60
def output_message(t, formatter)
  name = task_name(t)
  args = args_s(t)
  formatter.write do |w|
    w.info("Running task").notice(name).notice(args)
  end
end
task_name(t) click to toggle source
# File lib/fudge/tasks/composite_task.rb, line 52
def task_name(t)
  t.class.name.to_s
end
task_options(task_name) click to toggle source

Load the fudge_settings.yml for the current directory and return the options contained for the specified task

# File lib/fudge/tasks/composite_task.rb, line 33
def task_options(task_name)
  # are there settings for the specified task?
  settings = fudge_settings.fetch(task_name, {})
  key_syms = settings.map do |k, v|
    key = k.to_sym rescue k
    [key, v]
  end
  Hash[key_syms]
end