Class: Strobe::Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/strobe/settings.rb

Instance Method Summary collapse

Constructor Details

#initializeSettings

Returns a new instance of Settings.



5
6
7
8
9
10
# File 'lib/strobe/settings.rb', line 5

def initialize
  @location   = ENV["STROBE_SETTINGS"]   || Strobe.config_dir.join("config")
  @local      = ENV["STROBE_APP_CONFIG"] || Strobe.local_config_dir.join("config")
  @hash       = File.file?(@location) ? YAML.load(@location) : {}
  @local_hash = File.file?(@local)    ? YAML.load(@local)    : {}
end

Instance Method Details

#[](key) ⇒ Object



12
13
14
# File 'lib/strobe/settings.rb', line 12

def [](key)
  ENV[key_for(key)] || @local_hash[key_for(key)] || @hash[key_for(key)]
end

#[]=(key, value) ⇒ Object



16
17
18
19
20
# File 'lib/strobe/settings.rb', line 16

def []=(key, value)
  @hash[key_for(key)] = value
  File.open(@location, "wb") { |file| file.puts @hash.to_yaml }
  value
end

#app_connection_and_methodObject



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/strobe/settings.rb', line 38

def app_connection_and_method
  app_url = url("applications")

  if application = self[:application]
    app_url << "/#{application["id"]}"
    method = "PUT"
  else
    method = "POST"
  end

  return Excon::Connection.new(app_url), method
end

#auth_header(username = , password = nil) ⇒ Object



32
33
34
35
36
# File 'lib/strobe/settings.rb', line 32

def auth_header(username=self[:token], password=nil)
  header = "Basic " << ["#{username}:#{password}"].pack("m")
  header.gsub!(/\n/, '')
  {"Authorization" => header}
end

#set_local(key, value) ⇒ Object



22
23
24
25
# File 'lib/strobe/settings.rb', line 22

def set_local(key, value)
  @local_hash[key_for(key)] = value
  File.open(@local, "wb") { |file| file.puts @local_hash.to_yaml }
end

#url(path) ⇒ Object



27
28
29
30
# File 'lib/strobe/settings.rb', line 27

def url(path)
  self["url"] ||= "http://api.strobeapp.com/"
  self["url"] + path
end