Module: EnvHashConfig

Defined in:
lib/env_hash_config.rb,
lib/env_hash_config/version.rb

Constant Summary collapse

VERSION =
'1.1.0'

Class Method Summary collapse

Class Method Details

.create(options: ENV, array_options: [], boolean_options: [], default_options: {}, integer_options: []) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/env_hash_config.rb', line 5

def self.create(options: ENV, array_options: [], boolean_options: [], default_options: {}, integer_options: [])
  options = options.inject({}) { |h,(k,v)| h.tap { |h| h[k.downcase.to_sym] = v } }
  options = array_options.inject(options) { |h,k| h.tap { |h| h[k] = h[k].split ',' if h[k] } }
  options = boolean_options.inject(options) { |h,k| h.tap { |h| h[k] = h[k] == 'true' if h[k] } }
  options = integer_options.inject(options) { |h,k| h.tap { |h| h[k] = h[k].to_i if h[k] } }
  options = default_options.merge options
  options = yield options if block_given?

  OpenStruct.new options
end