Implement task evaluation feature

This commit is contained in:
Thibault Jouan
2013-07-27 23:53:12 +00:00
parent c7295fb977
commit baaa957e9e
6 changed files with 77 additions and 0 deletions

View File

@@ -13,11 +13,15 @@ module Producer
def evaluate
dsl = DSL.new(@code)
dsl.tasks.each.map(&:evaluate)
end
class DSL
attr_reader :tasks
def initialize(code = nil, &block)
@tasks = []
if code
instance_eval code
else
@@ -31,6 +35,10 @@ module Producer
def source(filepath)
instance_eval File.read("./#{filepath}.rb")
end
def task(name, &block)
@tasks << Task.new(name, &block)
end
end
end
end

16
lib/producer/core/task.rb Normal file
View File

@@ -0,0 +1,16 @@
module Producer
module Core
class Task
attr_reader :name
def initialize(name, &block)
@name = name
@block = block
end
def evaluate
instance_eval &@block
end
end
end
end