Class: Producer::Core::Task

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/producer/core/task.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env, name, actions = [], condition = true) ⇒ Task

Returns a new instance of Task.



35
36
37
38
39
40
# File 'lib/producer/core/task.rb', line 35

def initialize env, name, actions = [], condition = true
  @env        = env
  @name       = name
  @actions    = actions
  @condition  = condition
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



33
34
35
# File 'lib/producer/core/task.rb', line 33

def actions
  @actions
end

#condition(&block) ⇒ Object (readonly)

Returns the value of attribute condition.



33
34
35
# File 'lib/producer/core/task.rb', line 33

def condition
  @condition
end

#nameObject (readonly)

Returns the value of attribute name.



33
34
35
# File 'lib/producer/core/task.rb', line 33

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: build_prompter) ⇒ Object



55
56
57
# File 'lib/producer/core/task.rb', line 55

def ask question, choices, prompter: build_prompter
  prompter.prompt question, choices
end

#condition_met?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/producer/core/task.rb', line 42

def condition_met?
  !!@condition
end

#task(name, *args, &block) ⇒ Object



51
52
53
# File 'lib/producer/core/task.rb', line 51

def task name, *args, &block
  @actions << self.class.evaluate(@env, name, *args, &block)
end

#template(path, variables = {}) ⇒ Object



59
60
61
# File 'lib/producer/core/task.rb', line 59

def template path, variables = {}
  Template.new(path).render variables
end