Class: SettingsReader::Resolvers::Env

Inherits:
Abstract
  • Object
show all
Defined in:
lib/settings_reader/resolvers/env.rb

Overview

Resolve values in environment variable

Constant Summary collapse

IDENTIFIER =
'env://'.freeze

Constants included from Mixins::Values

Mixins::Values::PARSING_CLASSES

Instance Method Summary collapse

Methods included from Mixins::Values

#cast_value_from_string, #get_value_from_hash

Instance Method Details

#resolvable?(value, _path) ⇒ Boolean

Returns true when value starts from ‘env://`

Returns:

  • (Boolean)


8
9
10
11
12
# File 'lib/settings_reader/resolvers/env.rb', line 8

def resolvable?(value, _path)
  return unless value.respond_to?(:start_with?)

  value.start_with?(IDENTIFIER)
end

#resolve(value, _path) ⇒ Object

Return value of environment variable by removing ‘env://` prefix and calling `ENV`



15
16
17
18
# File 'lib/settings_reader/resolvers/env.rb', line 15

def resolve(value, _path)
  env_path = value.to_s.delete_prefix(IDENTIFIER)
  ENV[env_path]
end