Top Level Namespace

Defined Under Namespace

Modules: Sunrise

Constant Summary collapse

CONFIG_FNAME =
"#{ENV['HOME']}/.sunrisehq"
DEVCONFIG_FNAME =
"#{ENV['HOME']}/.sunrisehq-dev"

Instance Method Summary collapse

Instance Method Details

#settings(options = nil) ⇒ Object

Load settings from the config and developer config files, and apply current overrides from options



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'bin/sunrise', line 14

def settings(options = nil)
  if File.exists?(CONFIG_FNAME)
    settings = YAML.load( File.read(CONFIG_FNAME) )
  else
    settings = {}
  end
  if options
    # Override default settings with command-line options
    settings.merge!({ 'login'        => options['login'] }) if options['login']
    settings.merge!({ 'password'     => options['password'] }) if options['password']
    settings.merge!({ 'default_team' => options['team'] }) if options['team']
  end
  if File.exists?(DEVCONFIG_FNAME)
    # Merge in developer settings as well
    settings.merge!( YAML.load( File.read(DEVCONFIG_FNAME) ) )
  else
    # Set default (production) host/port
    settings.merge!({ 'host' => 'sunrisehq.com', 'port' => 80 })
  end
  settings
end

#setup_sunrise_client(options = nil) ⇒ Object

Get a properly configured sunrise::Client



37
38
39
# File 'bin/sunrise', line 37

def setup_sunrise_client(options = nil)
  Sunrise::Client.new(settings(options)['login'], settings(options)['password'], settings(options)['host'], settings(options)['port'])
end