Module: ConsulApplicationSettings::Utils

Defined in:
lib/consul_application_settings/utils.rb

Overview

Utility methods to cast values and work with path

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.cast_consul_value(value) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/consul_application_settings/utils.rb', line 8

def cast_consul_value(value)
  return nil if value.nil?
  return false if value == 'false'
  return true if value == 'true'

  cast_complex_value(value)
end

.decompose_path(path) ⇒ Object



22
23
24
25
# File 'lib/consul_application_settings/utils.rb', line 22

def decompose_path(path)
  parts = path.to_s.split(SEPARATOR).compact
  parts.reject(&:empty?)
end

.generate_path(*parts) ⇒ Object



16
17
18
19
20
# File 'lib/consul_application_settings/utils.rb', line 16

def generate_path(*parts)
  strings = parts.map(&:to_s)
  all_parts = strings.map { |s| s.split(SEPARATOR) }.flatten
  all_parts.reject(&:empty?).join('/')
end