Class: Discharger::SetupRunner::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/discharger/setup_runner/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_rootObject (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_factoryObject (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

#configObject (readonly)

Returns the value of attribute config.



12
13
14
# File 'lib/discharger/setup_runner/runner.rb', line 12

def config
  @config
end

#loggerObject (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

#runObject



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.message}").bright.red
  end
  raise Error, e.message
end