Class: Blazing::Commands

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/blazing/commands.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Commands

Returns a new instance of Commands.


15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/blazing/commands.rb', line 15

def initialize(options = {})
  warn 'The :default Target option has been deprecated and will be ignored' if options.key?(:default)
  @cli_options = options[:cli_options]
  @target_name = options[:target_name]
  @config_file = options[:file]
  @command = options[:command]
  @targets = []

  return unless command_requires_config?

  @config ||= Blazing::Config.parse(@config_file)
  @targets = determine_targets
  error 'no target given or found' if @targets.empty?
end

Class Method Details

.run(command, options = {}) ⇒ Object


10
11
12
# File 'lib/blazing/commands.rb', line 10

def run(command, options = {})
  new(options.merge(command: command)).send(command)
end

Instance Method Details

#gotoObject


46
47
48
49
50
51
52
53
54
55
# File 'lib/blazing/commands.rb', line 46

def goto
  # TODO: Would be nice to detect zsh and use it instead of bash?
  @targets.each do |target|
    if @cli_options[:run]
      system "ssh -t -t #{target.user}@#{target.host} 'cd #{target.path} && RAILS_ENV=#{target.options[:rails_env]} bash --login -c \"#{@cli_options[:run]}\"'"
    else
      system "ssh -t -t #{target.user}@#{target.host} 'cd #{target.path} && RAILS_ENV=#{target.options[:rails_env]} bash --login'"
    end
  end
end

#initObject


30
31
32
33
34
35
# File 'lib/blazing/commands.rb', line 30

def init
  info "Creating an example config file in #{Blazing::DEFAULT_CONFIG_LOCATION}"
  info 'Customize it to your needs'
  create_config_directory
  write_config_file
end

#setupObject


37
38
39
40
# File 'lib/blazing/commands.rb', line 37

def setup
  @targets.each(&:setup)
  update
end

#updateObject


42
43
44
# File 'lib/blazing/commands.rb', line 42

def update
  @targets.each(&:update)
end