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



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

def initialize(options = {})
  warn 'The :default Target option has been deprecated and will be ignored' if options.has_key?(:default)
  @cli_options = options[:options] # that stinks! TODO: clean up options handling.
  @target_name = options[:target_name]
  @config_file = options[:file]
  @command = options[:command]
  @targets = []

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

Class Method Details

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



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

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

Instance Method Details

#gotoObject



49
50
51
52
53
54
55
56
57
58
# File 'lib/blazing/commands.rb', line 49

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



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

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

#listObject



60
61
62
# File 'lib/blazing/commands.rb', line 60

def list
  Blazing::Recipe.pretty_list
end

#recipesObject



45
46
47
# File 'lib/blazing/commands.rb', line 45

def recipes
  @config.recipes.each { |recipe| recipe.run({:target_name => @target_name}) }
end

#setupObject



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

def setup
  @targets.each { |target| target.setup }
  update
end

#updateObject



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

def update
  @targets.each { |target| target.update }
end