Class: Chordate::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/chordate-ruby/config.rb

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/chordate-ruby/config.rb', line 3

def initialize
  @config = {
    'env' => rails(:env) || 'default',
    'proto' => 'https://',
    'host' => "chordate.io",
    'server' => {
      :root => rails(:root) || `pwd`.chomp,
      :hostname => `hostname`.chomp,
      :gem_version => Chordate::Version::STRING
    }
  }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/chordate-ruby/config.rb', line 28

def method_missing(meth, *args)
  case meth
  when /=$/
    @config[meth.to_s[0..-2]] = args.first
  else
    @config[meth.to_s]
  end
end

Instance Method Details

#[](key) ⇒ Object



16
17
18
# File 'lib/chordate-ruby/config.rb', line 16

def [](key)
  @config[key.to_s]
end

#token=(token) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/chordate-ruby/config.rb', line 20

def token=(token)
  token = token.split(':')

  (@config['token'] = token[1]).tap do
    @config['base_url'] ||= "/v1/applications/#{token[0]}"
  end
end