Class: Producer::Core::Task
- Inherits:
-
Object
- Object
- Producer::Core::Task
- Extended by:
- Forwardable
- Defined in:
- lib/producer/core/task.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#condition(&block) ⇒ Object
readonly
Returns the value of attribute condition.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #ask(question, choices, prompter: Prompter.new(@env.input, @env.output)) ⇒ Object
- #condition_met? ⇒ Boolean
-
#initialize(env, name, actions = [], condition = true) ⇒ Task
constructor
A new instance of Task.
- #task(name, *args, &block) ⇒ Object
- #template(path, variables = {}) ⇒ Object
Constructor Details
#initialize(env, name, actions = [], condition = true) ⇒ Task
Returns a new instance of Task.
33 34 35 36 37 38 |
# File 'lib/producer/core/task.rb', line 33 def initialize(env, name, actions = [], condition = true) @env = env @name = name @actions = actions @condition = condition end |
Instance Attribute Details
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
31 32 33 |
# File 'lib/producer/core/task.rb', line 31 def actions @actions end |
#condition(&block) ⇒ Object (readonly)
Returns the value of attribute condition.
31 32 33 |
# File 'lib/producer/core/task.rb', line 31 def condition @condition end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
31 32 33 |
# File 'lib/producer/core/task.rb', line 31 def name @name end |
Class Method Details
.define_action(keyword, klass) ⇒ Object
5 6 7 8 9 |
# File 'lib/producer/core/task.rb', line 5 def define_action(keyword, klass) define_method(keyword) do |*args| @actions << klass.new(@env, *args) end end |
.evaluate(env, name, *args, &block) ⇒ Object
11 12 13 |
# File 'lib/producer/core/task.rb', line 11 def evaluate(env, name, *args, &block) new(env, name).tap { |o| o.instance_exec *args, &block } end |
Instance Method Details
#ask(question, choices, prompter: Prompter.new(@env.input, @env.output)) ⇒ Object
53 54 55 |
# File 'lib/producer/core/task.rb', line 53 def ask(question, choices, prompter: Prompter.new(@env.input, @env.output)) prompter.prompt(question, choices) end |
#condition_met? ⇒ Boolean
40 41 42 |
# File 'lib/producer/core/task.rb', line 40 def condition_met? !!@condition end |
#task(name, *args, &block) ⇒ Object
49 50 51 |
# File 'lib/producer/core/task.rb', line 49 def task(name, *args, &block) @actions << self.class.evaluate(@env, name, *args, &block) end |