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



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/configature/support.rb', line 27

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



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/configature/support.rb', line 15

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
13
# File 'lib/configature/support.rb', line 6

def yaml_if_exist(path)
  return unless (File.exist?(path))
  
  # FIX: Use safe_load if safe_load supports aliases
  File.open(path) do |f|
    YAML.load(f)
  end
end