Module: SettingsReader::Mixins::Values

Included in:
Backends::Abstract, Resolvers::Abstract
Defined in:
lib/settings_reader/mixins/values.rb

Overview

Value casting utility methods

Constant Summary collapse

PARSING_CLASSES =
[Integer, Float, ->(value) { JSON.parse(value) }].freeze

Instance Method Summary collapse

Instance Method Details

#cast_value_from_string(value) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/settings_reader/mixins/values.rb', line 7

def cast_value_from_string(value)
  return nil if value.nil?
  return false if value == 'false'
  return true if value == 'true'
  return value if value.is_a?(Hash)
  return convert_to_hash(value) if value.is_a?(Array)

  cast_complex_value(value)
end

#get_value_from_hash(data, path_parts) ⇒ Object



17
18
19
# File 'lib/settings_reader/mixins/values.rb', line 17

def get_value_from_hash(data, path_parts)
  data.dig(*path_parts).clone
end