Class: Producer::Core::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/producer/core/worker.rb

Constant Summary collapse

DRY_RUN_WARNING =
'running in dry run mode, actions will NOT be applied'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ Worker

Returns a new instance of Worker.



7
8
9
# File 'lib/producer/core/worker.rb', line 7

def initialize(env)
  @env = env
end

Instance Method Details

#process(tasks) ⇒ Object



11
12
13
14
15
# File 'lib/producer/core/worker.rb', line 11

def process(tasks)
  @env.log DRY_RUN_WARNING, :warn if @env.dry_run?

  tasks.each { |t| process_task t }
end

#process_task(task, indent_level = 0) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/producer/core/worker.rb', line 17

def process_task(task, indent_level = 0)
  if task.condition_met?
    log "Task: `#{task}' applying...", indent_level
    task.actions.each do |e|
      case e
      when Task then process_task e, indent_level + 2
      else
        log " action: #{e}", indent_level
        e.apply unless @env.dry_run?
      end
    end
  else
    log "Task: `#{task}' skipped", indent_level
  end
end