Class: Eclair::Config

Inherits:
Object
  • Object
show all
Includes:
Curses
Defined in:
lib/eclair/config.rb

Constant Summary collapse

RCFILE =
ENV["ECLRC"] || "#{ENV['HOME']}/.eclrc"

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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/eclair/config.rb', line 6

def initialize
  @aws_region = nil
  @columns = 4
  @group_by = lambda do |instance|
    if instance.security_groups.first
      instance.security_groups.first.group_name
    else
      "no_group"
    end
  end
  @ssh_username = lambda do |image|
    case image.name
    when /ubuntu/
      "ubuntu"
    else
      "ec2-user"
    end
  end
  @ssh_hostname         = :public_ip_address
  @ssh_ports            = [22].freeze
  @ssh_options          = "-o ConnectTimeout=1 -o StrictHostKeyChecking=no".freeze
  @instance_color       = [COLOR_WHITE, -1].freeze
  @group_color          = [COLOR_WHITE, -1, A_BOLD].freeze
  @current_color        = [COLOR_BLACK, COLOR_CYAN].freeze
  @selected_color       = [COLOR_YELLOW, -1, A_BOLD].freeze
  @disabled_color       = [COLOR_BLACK, -1, A_BOLD].freeze
  @search_color         = [COLOR_BLACK, COLOR_YELLOW].freeze
  @help_color           = [COLOR_BLACK, COLOR_WHITE].freeze

  instance_variables.each do |var|
    Config.class_eval do
      attr_accessor var.to_s.tr("@","").to_sym
    end
  end

  unless File.exists? RCFILE
    template_path = File.join(File.dirname(__FILE__), "..", "..", "templates", "eclrc.template")
    FileUtils.cp(template_path, RCFILE)
    puts "#{RCFILE} successfully created. Edit it and run again!"
    exit
  end
end