Class: Suzanne::EnvReader

Inherits:
Object
  • Object
show all
Defined in:
lib/suzanne/env_reader.rb

Defined Under Namespace

Classes: MissingKey

Instance Method Summary collapse

Constructor Details

#initialize(config_hash) ⇒ EnvReader

ENV takes priority over config_hash



12
13
14
# File 'lib/suzanne/env_reader.rb', line 12

def initialize(config_hash)
  @env = config_hash.merge(ENV)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method) ⇒ Object (private)



37
38
39
40
41
42
43
44
45
# File 'lib/suzanne/env_reader.rb', line 37

def method_missing(method, *)
  key, punctuation = extract_key_from_method(method)

  return fetch_key!(key) if punctuation == '!'
  return !!send(key) if punctuation == '?'
  return get_value(key) if key && !punctuation
rescue NoMethodError
  super
end

Instance Method Details

#inspectObject



20
21
22
# File 'lib/suzanne/env_reader.rb', line 20

def inspect
  'Suzanne env'
end

#respond_to?(method) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
# File 'lib/suzanne/env_reader.rb', line 24

def respond_to?(method, *)
  key, punctuation = extract_key_from_method(method)

  return true if punctuation == '?'
  return (key?(key) || super) if punctuation == '!'

  true
end

#to_sObject



16
17
18
# File 'lib/suzanne/env_reader.rb', line 16

def to_s
  'Suzanne env'
end