module Configature::Support

Public Instance Methods

convert_hashes(to_class, obj) click to toggle source
# File lib/configature/support.rb, line 26
def convert_hashes(to_class, obj)
  case (obj)
  when Hash, OpenStruct, Configature::Data
    to_class.new(
      obj.to_h.map do |k, v|
        [ k, convert_hashes(to_class, v) ]
      end.to_h
    )
  when Array
    obj.map do |v|
      convert_hashes(to_class, v)
    end
  else
    obj
  end
end
extend_env_prefix(base, with) click to toggle source
# File lib/configature/support.rb, line 14
def extend_env_prefix(base, with)
  return base unless (base)
  return with unless (with)

  case (base)
  when ''
    with.to_s.upcase
  else
    base.upcase + '_' + with.to_s.upcase
  end
end
yaml_if_exist(path) click to toggle source

Module and Mixin Methods =============================================

# File lib/configature/support.rb, line 6
def yaml_if_exist(path)
  return unless (File.exist?(path))

  File.open(path) do |f|
    YAML.safe_load(f, aliases: true) or { }
  end
end