Class: Discharger::SetupRunner::Runner
- Inherits:
-
Object
- Object
- Discharger::SetupRunner::Runner
- Defined in:
- lib/discharger/setup_runner/runner.rb
Instance Attribute Summary collapse
-
#app_root ⇒ Object
readonly
Returns the value of attribute app_root.
-
#command_factory ⇒ Object
readonly
Returns the value of attribute command_factory.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
- #add_command(command) ⇒ Object
-
#initialize(config, app_root = nil, logger = nil) ⇒ Runner
constructor
A new instance of Runner.
- #insert_command_after(target_command_name, new_command) ⇒ Object
- #insert_command_before(target_command_name, new_command) ⇒ Object
- #remove_command(command_name) ⇒ Object
- #replace_command(command_name, new_command) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(config, app_root = nil, logger = nil) ⇒ Runner
Returns a new instance of Runner.
14 15 16 17 18 19 |
# File 'lib/discharger/setup_runner/runner.rb', line 14 def initialize(config, app_root = nil, logger = nil) @config = config @app_root = app_root || Dir.pwd @logger = logger || Logger.new($stdout) @command_factory = CommandFactory.new(config, app_root, logger) end |
Instance Attribute Details
#app_root ⇒ Object (readonly)
Returns the value of attribute app_root.
12 13 14 |
# File 'lib/discharger/setup_runner/runner.rb', line 12 def app_root @app_root end |
#command_factory ⇒ Object (readonly)
Returns the value of attribute command_factory.
12 13 14 |
# File 'lib/discharger/setup_runner/runner.rb', line 12 def command_factory @command_factory end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
12 13 14 |
# File 'lib/discharger/setup_runner/runner.rb', line 12 def config @config end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
12 13 14 |
# File 'lib/discharger/setup_runner/runner.rb', line 12 def logger @logger end |
Instance Method Details
#add_command(command) ⇒ Object
42 43 44 |
# File 'lib/discharger/setup_runner/runner.rb', line 42 def add_command(command) commands << command end |
#insert_command_after(target_command_name, new_command) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/discharger/setup_runner/runner.rb', line 64 def insert_command_after(target_command_name, new_command) target_index = commands.find_index { |cmd| cmd.class.name.demodulize.underscore == target_command_name.to_s } if target_index commands.insert(target_index + 1, new_command) else add_command(new_command) end end |
#insert_command_before(target_command_name, new_command) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/discharger/setup_runner/runner.rb', line 55 def insert_command_before(target_command_name, new_command) target_index = commands.find_index { |cmd| cmd.class.name.demodulize.underscore == target_command_name.to_s } if target_index commands.insert(target_index, new_command) else add_command(new_command) end end |
#remove_command(command_name) ⇒ Object
46 47 48 |
# File 'lib/discharger/setup_runner/runner.rb', line 46 def remove_command(command_name) commands.reject! { |cmd| cmd.class.name.demodulize.underscore == command_name.to_s } end |
#replace_command(command_name, new_command) ⇒ Object
50 51 52 53 |
# File 'lib/discharger/setup_runner/runner.rb', line 50 def replace_command(command_name, new_command) remove_command(command_name) add_command(new_command) end |
#run ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/discharger/setup_runner/runner.rb', line 21 def run require "rainbow" unless ENV["QUIET_SETUP"] || ENV["DISABLE_OUTPUT"] puts Rainbow("\nš Starting setup for #{config.app_name}").bright.blue puts Rainbow("=" * 50).blue end FileUtils.chdir app_root do execute_commands end unless ENV["QUIET_SETUP"] || ENV["DISABLE_OUTPUT"] puts Rainbow("\nā Setup completed successfully!").bright.green end rescue => e unless ENV["QUIET_SETUP"] || ENV["DISABLE_OUTPUT"] puts Rainbow("\nā Setup failed: #{e.}").bright.red end raise Error, e. end |