Class: Molder::App

Inherits:
Object
  • Object
show all
Defined in:
lib/molder/app.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config:, options:, command_name:) ⇒ App

Returns a new instance of App.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/molder/app.rb', line 11

def initialize(config:, options:, command_name:)
  self.config       = config
  self.options      = options
  self.command_name = command_name
  self.commands     = []
  self.log_dir      = options[:log_dir] || config.global.log_dir || './log'

  resolve_command!

  resolve_templates!
end

Instance Attribute Details

#commandObject

Returns the value of attribute command.



9
10
11
# File 'lib/molder/app.rb', line 9

def command
  @command
end

#command_nameObject

Returns the value of attribute command_name.



9
10
11
# File 'lib/molder/app.rb', line 9

def command_name
  @command_name
end

#commandsObject

Returns the value of attribute commands.



9
10
11
# File 'lib/molder/app.rb', line 9

def commands
  @commands
end

#configObject

Returns the value of attribute config.



9
10
11
# File 'lib/molder/app.rb', line 9

def config
  @config
end

#log_dirObject

Returns the value of attribute log_dir.



9
10
11
# File 'lib/molder/app.rb', line 9

def log_dir
  @log_dir
end

#optionsObject

Returns the value of attribute options.



9
10
11
# File 'lib/molder/app.rb', line 9

def options
  @options
end

#templatesObject

Returns the value of attribute templates.



9
10
11
# File 'lib/molder/app.rb', line 9

def templates
  @templates
end

Instance Method Details

#execute!Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/molder/app.rb', line 23

def execute!
    colors = i(yellow blue red green magenta cyan white)

    FileUtils.mkdir_p(log_dir)
    if options.dry_run
      puts "\nDry-run print of #{commands.size} commands:\n".bold.cyan.underlined
      commands.count.times do |i|
        color = colors[i % colors.size]
        cmd   = commands[i ]
        puts "#{cmd}\n".send(color).send(:bold)
      end
    else
      puts "Executing #{commands.size} commands using a pool of up to #{options.max_processes} processes:\n".bold.cyan.underlined
      ::Parallel.each((1..commands.size),
                      :in_processes => options.max_processes) do |i|

        color = colors[(i - 1) % colors.size]
        cmd   = commands[i - 1]
        printf('%s', "Worker: #{Parallel.worker_number}, command #{i}\n".send(color)) if options.verbose
        puts "#{cmd}\n".send(color)

        system %Q(( #{cmd} ) > #{log_dir}/#{command_name}.#{i}.log)
    end
  end
end