Class: Flow::Config

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/flow/config.rb

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



8
9
10
# File 'lib/flow/config.rb', line 8

def initialize
  @config = self.defaults
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/flow/config.rb', line 19

def method_missing(meth, *args, &block)
  meth_str = meth.to_s

  if /^(\w+)=$/.match(meth_str)
    _set($1, args.first)
  else
    _get(meth)
  end
end

Instance Method Details

#defaultsObject



12
13
14
15
16
17
# File 'lib/flow/config.rb', line 12

def defaults
  {
    url: 'https://flow.ribbon.co'.freeze,
    api_key: nil
  }
end

#to_sObject



35
36
37
# File 'lib/flow/config.rb', line 35

def to_s
  return @config.to_s
end

#url=(url) ⇒ Object



29
30
31
32
33
# File 'lib/flow/config.rb', line 29

def url=(url)
  raise Flow::Errors::ConfigError, "URL must be defined" unless url
  url = url[0..-2] if url[-1] == '/' # No trailing forward-slash
  _set(:url, url)
end