Class: Molder::App
- Inherits:
-
Object
- Object
- Molder::App
- Defined in:
- lib/molder/app.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
Returns the value of attribute command.
-
#command_name ⇒ Object
Returns the value of attribute command_name.
-
#commands ⇒ Object
Returns the value of attribute commands.
-
#config ⇒ Object
Returns the value of attribute config.
-
#log_dir ⇒ Object
Returns the value of attribute log_dir.
-
#options ⇒ Object
Returns the value of attribute options.
-
#templates ⇒ Object
Returns the value of attribute templates.
Instance Method Summary collapse
- #execute! ⇒ Object
-
#initialize(config:, options:, command_name:) ⇒ App
constructor
A new instance of App.
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. = self.command_name = command_name self.commands = [] self.log_dir = [:log_dir] || config.global.log_dir || './log' resolve_command! resolve_templates! end |
Instance Attribute Details
#command ⇒ Object
Returns the value of attribute command.
9 10 11 |
# File 'lib/molder/app.rb', line 9 def command @command end |
#command_name ⇒ Object
Returns the value of attribute command_name.
9 10 11 |
# File 'lib/molder/app.rb', line 9 def command_name @command_name end |
#commands ⇒ Object
Returns the value of attribute commands.
9 10 11 |
# File 'lib/molder/app.rb', line 9 def commands @commands end |
#config ⇒ Object
Returns the value of attribute config.
9 10 11 |
# File 'lib/molder/app.rb', line 9 def config @config end |
#log_dir ⇒ Object
Returns the value of attribute log_dir.
9 10 11 |
# File 'lib/molder/app.rb', line 9 def log_dir @log_dir end |
#options ⇒ Object
Returns the value of attribute options.
9 10 11 |
# File 'lib/molder/app.rb', line 9 def end |
#templates ⇒ Object
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 .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 => .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 .verbose puts "#{cmd}\n".send(color) system %Q(( #{cmd} ) > #{log_dir}/#{command_name}.#{i}.log) end end end |