class Crew::Task::DSL

Public Class Methods

new(task, &blk) click to toggle source
# File lib/crew/task/dsl.rb, line 6
def initialize(task, &blk)
  @task = task
  self._arguments = @task.arguments
  instance_eval(&blk) if blk
end

Public Instance Methods

block(opts = {}, &blk) click to toggle source
# File lib/crew/task/dsl.rb, line 42
def block(opts = {}, &blk)
  @task.arguments.define_block(opts, &blk)
end
desc(val) click to toggle source
# File lib/crew/task/dsl.rb, line 18
def desc(val)
  @task.desc = val
end
hints(*hints) click to toggle source
# File lib/crew/task/dsl.rb, line 22
def hints(*hints)
  @task.default_hints = hints
end
load(path) click to toggle source
# File lib/crew/task/dsl.rb, line 12
def load(path)
  contents = File.read(path)
  instance_eval(contents, path, 1)
  process_templates contents.split("__END__\n", 2)[1]
end
run(*hints, &blk) click to toggle source
# File lib/crew/task/dsl.rb, line 30
def run(*hints, &blk)
  add_to_task(:run, hints, blk)
end
setup(*hints, &blk) click to toggle source
# File lib/crew/task/dsl.rb, line 26
def setup(*hints, &blk)
  add_to_task(:setup, hints, blk)
end
test(*hints, &blk) click to toggle source
# File lib/crew/task/dsl.rb, line 38
def test(*hints, &blk)
  add_to_task(:test, hints, blk)
end
verify(*hints, &blk) click to toggle source
# File lib/crew/task/dsl.rb, line 34
def verify(*hints, &blk)
  add_to_task(:verify, hints, blk)
end

Private Instance Methods

add_to_task(type, hints, handler) click to toggle source
# File lib/crew/task/dsl.rb, line 47
def add_to_task(type, hints, handler)
  method_name = "add_#{type}"
  if hints.empty?
    @task.send(method_name, &handler)
  else
    hints.each { |hint| @task.send(method_name, hint, &handler) }
  end
end
process_templates(data) click to toggle source
# File lib/crew/task/dsl.rb, line 56
def process_templates(data)
  return unless data
  templates = {}
  last_name = nil
  data.each_line do |line|
    if name = line[/^@@ (.*)\n/, 1]
      templates[name] = ''
      last_name = name
    elsif !last_name
      raise
    else
      templates[last_name] << line
    end
  end
  templates.each do |name, contents|
    @task.add_template name, contents
  end
end