Implement basic task actions API:
* Add Action base class; * Implement Task::DSL.define_action(keyword, klass); * Add Task::DSL#actions accessor; * Apply task DSL actions when Task instances are evaluated.
This commit is contained in:
12
lib/producer/core/action.rb
Normal file
12
lib/producer/core/action.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
module Producer
|
||||
module Core
|
||||
class Action
|
||||
attr_accessor :env, :arguments
|
||||
|
||||
def initialize(env, *args)
|
||||
@env = env
|
||||
@arguments = args
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -9,7 +9,9 @@ module Producer
|
||||
end
|
||||
|
||||
def evaluate(env)
|
||||
DSL.new(&@block).evaluate(env)
|
||||
dsl = DSL.new(&@block)
|
||||
dsl.evaluate(env)
|
||||
dsl.actions.map(&:apply)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -2,11 +2,23 @@ module Producer
|
||||
module Core
|
||||
class Task
|
||||
class DSL
|
||||
class << self
|
||||
def define_action(keyword, klass)
|
||||
define_method(keyword) do |*args|
|
||||
@actions << klass.new(@env, *args)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
attr_accessor :actions
|
||||
|
||||
def initialize(&block)
|
||||
@block = block
|
||||
@block = block
|
||||
@actions = []
|
||||
end
|
||||
|
||||
def evaluate(env)
|
||||
@env = env
|
||||
instance_eval &@block
|
||||
rescue ConditionNotMetError
|
||||
rescue NameError => e
|
||||
|
Reference in New Issue
Block a user