module ConsulApplicationSettings::Utils

Utility methods to cast values and work with path

Constants

PARSING_CLASSES
SEPARATOR

Public Class Methods

cast_consul_value(value) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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

Protected Class Methods

cast_complex_value(value) click to toggle source
# File lib/consul_application_settings/utils.rb, line 29
def cast_complex_value(value)
  PARSING_CLASSES.each do |parser|
    return parser.call(value)
  rescue StandardError => _e
    nil
  end
  value.to_s
end