Module: Configature::Support

Extended by:
Support
Included in:
Support
Defined in:
lib/configature/support.rb

Instance Method Summary collapse

Instance Method Details

#convert_hashes(to_class, obj) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# 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) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# 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) ⇒ Object

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



6
7
8
9
10
11
12
# 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