Class: ENVied::EnvProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/envied/env_proxy.rb

Overview

Responsible for anything related to the ENV.

Instance Method Summary collapse

Constructor Details

#initialize(config, **options) ⇒ EnvProxy

Returns a new instance of EnvProxy.



7
8
9
10
11
# File 'lib/envied/env_proxy.rb', line 7

def initialize(config, **options)
  @config = config
  @coercer = options.fetch(:coercer, ENVied::Coercer.new)
  @groups = options.fetch(:groups, [])
end

Instance Method Details

#[](name) ⇒ Object



21
22
23
# File 'lib/envied/env_proxy.rb', line 21

def [](name)
  coerce(variables_by_name[name.to_sym])
end

#has_key?(name) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/envied/env_proxy.rb', line 25

def has_key?(name)
  variables_by_name[name.to_sym]
end

#missing_variablesObject



13
14
15
# File 'lib/envied/env_proxy.rb', line 13

def missing_variables
  variables.select(&method(:missing?))
end

#uncoercible_variablesObject



17
18
19
# File 'lib/envied/env_proxy.rb', line 17

def uncoercible_variables
  variables.reject(&method(:coerced?)).reject(&method(:coercible?))
end

#value_to_coerce(var) ⇒ Object



29
30
31
32
# File 'lib/envied/env_proxy.rb', line 29

def value_to_coerce(var)
  return env_value_of(var) unless env_value_of(var).nil?
  config.defaults_enabled? ? default_value_of(var) : nil
end