class Suzanne::EnvReader

Attributes

env[R]

Public Class Methods

new(config_hash) click to toggle source

ENV takes priority over config_hash

# File lib/suzanne/env_reader.rb, line 12
def initialize(config_hash)
  @env = config_hash.merge(ENV)
end

Public Instance Methods

inspect() click to toggle source
# File lib/suzanne/env_reader.rb, line 20
def inspect
  'Suzanne env'
end
respond_to?(method, *) click to toggle source
Calls superclass method
# 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_s() click to toggle source
# File lib/suzanne/env_reader.rb, line 16
def to_s
  'Suzanne env'
end

Private Instance Methods

extract_key_from_method(method) click to toggle source
# File lib/suzanne/env_reader.rb, line 60
def extract_key_from_method(method)
  method.to_s.downcase.match(%r{^(.+?)([!?=])?$}).captures
end
fetch_key!(key) click to toggle source
# File lib/suzanne/env_reader.rb, line 56
def fetch_key!(key)
  send(key) || missing_key!(key)
end
get_value(key) click to toggle source
# File lib/suzanne/env_reader.rb, line 72
def get_value(key)
  _, value = env.detect { |k, _v| k.downcase == key }
  value
end
key?(key) click to toggle source
# File lib/suzanne/env_reader.rb, line 64
def key?(key)
  env.any? { |k, _| k.downcase == key }
end
method_missing(method, *) click to toggle source
Calls superclass method
# 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
missing_key!(key) click to toggle source
# File lib/suzanne/env_reader.rb, line 68
def missing_key!(key)
  raise MissingKey.new(key) # rubocop:disable Style/RaiseArgs
end
respond_to_missing?(method, *) click to toggle source
Calls superclass method
# File lib/suzanne/env_reader.rb, line 47
def respond_to_missing?(method, *)
  key, punctuation = extract_key_from_method(method)

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

  true
end