Refactor with Forwardable module
This commit is contained in:
parent
af1bb97287
commit
86a84bbe12
@ -1,6 +1,9 @@
|
|||||||
module Producer
|
module Producer
|
||||||
module Core
|
module Core
|
||||||
class Env
|
class Env
|
||||||
|
extend Forwardable
|
||||||
|
def_delegators :@registry, :[]=
|
||||||
|
|
||||||
attr_reader :input, :output, :error_output, :registry, :logger
|
attr_reader :input, :output, :error_output, :registry, :logger
|
||||||
attr_accessor :target, :verbose, :debug, :dry_run
|
attr_accessor :target, :verbose, :debug, :dry_run
|
||||||
|
|
||||||
@ -24,10 +27,6 @@ module Producer
|
|||||||
end
|
end
|
||||||
alias get []
|
alias get []
|
||||||
|
|
||||||
def []=(key, value)
|
|
||||||
@registry[key] = value
|
|
||||||
end
|
|
||||||
|
|
||||||
def logger
|
def logger
|
||||||
@logger ||= begin
|
@logger ||= begin
|
||||||
logger = Logger.new(output)
|
logger = Logger.new(output)
|
||||||
|
@ -19,6 +19,9 @@ module Producer
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
extend Forwardable
|
||||||
|
def_delegator :@env, :[]=, :set
|
||||||
|
def_delegator :@env, :[], :get
|
||||||
attr_reader :env, :tasks
|
attr_reader :env, :tasks
|
||||||
|
|
||||||
def initialize(env)
|
def initialize(env)
|
||||||
@ -49,14 +52,6 @@ module Producer
|
|||||||
def test_macro(name, &block)
|
def test_macro(name, &block)
|
||||||
Condition.define_test(name, block)
|
Condition.define_test(name, block)
|
||||||
end
|
end
|
||||||
|
|
||||||
def set(key, value)
|
|
||||||
env[key] = value
|
|
||||||
end
|
|
||||||
|
|
||||||
def get(key)
|
|
||||||
env[key]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -14,7 +14,9 @@ module Producer
|
|||||||
end
|
end
|
||||||
|
|
||||||
extend Forwardable
|
extend Forwardable
|
||||||
def_delegators :@env, :target
|
def_delegators :@name, :to_s
|
||||||
|
def_delegators :@env, :target
|
||||||
|
def_delegator :@env, :[], :get
|
||||||
|
|
||||||
define_action :echo, Actions::Echo
|
define_action :echo, Actions::Echo
|
||||||
define_action :sh, Actions::ShellCommand
|
define_action :sh, Actions::ShellCommand
|
||||||
@ -34,10 +36,6 @@ module Producer
|
|||||||
@condition = condition
|
@condition = condition
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
|
||||||
@name.to_s
|
|
||||||
end
|
|
||||||
|
|
||||||
def condition_met?
|
def condition_met?
|
||||||
!!@condition
|
!!@condition
|
||||||
end
|
end
|
||||||
@ -55,10 +53,6 @@ module Producer
|
|||||||
prompter.prompt(question, choices)
|
prompter.prompt(question, choices)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get(key)
|
|
||||||
@env[key]
|
|
||||||
end
|
|
||||||
|
|
||||||
def template(path, variables = {})
|
def template(path, variables = {})
|
||||||
Template.new(path).render variables
|
Template.new(path).render variables
|
||||||
end
|
end
|
||||||
|
@ -2,9 +2,9 @@ module Producer
|
|||||||
module Core
|
module Core
|
||||||
module Tests
|
module Tests
|
||||||
class ConditionTest < Test
|
class ConditionTest < Test
|
||||||
def verify
|
extend Forwardable
|
||||||
condition.met?
|
def_delegator :@arguments, :first, :condition_block
|
||||||
end
|
def_delegator :condition, :met?, :verify
|
||||||
|
|
||||||
def condition
|
def condition
|
||||||
Condition.evaluate(env, *condition_args, &condition_block)
|
Condition.evaluate(env, *condition_args, &condition_block)
|
||||||
@ -13,10 +13,6 @@ module Producer
|
|||||||
def condition_args
|
def condition_args
|
||||||
arguments.drop 1
|
arguments.drop 1
|
||||||
end
|
end
|
||||||
|
|
||||||
def condition_block
|
|
||||||
arguments.first
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,16 +2,15 @@ module Producer
|
|||||||
module Core
|
module Core
|
||||||
module Tests
|
module Tests
|
||||||
class ShellCommandStatus < Test
|
class ShellCommandStatus < Test
|
||||||
|
extend Forwardable
|
||||||
|
def_delegator :@arguments, :first, :command
|
||||||
|
|
||||||
def verify
|
def verify
|
||||||
remote.execute(command)
|
remote.execute(command)
|
||||||
true
|
true
|
||||||
rescue RemoteCommandExecutionError
|
rescue RemoteCommandExecutionError
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
def command
|
|
||||||
arguments.first
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user