Module: ConfigToEnv
- Defined in:
- lib/config_to_env.rb
Class Method Summary collapse
- .flat_hash?(hash) ⇒ Boolean
-
.flatten_hash(hash) ⇒ Object
Take a hash, and flatten it down to a simple key/value pair hash.
- .is_value?(node) ⇒ Boolean
Class Method Details
.flat_hash?(hash) ⇒ Boolean
30 31 32 33 34 |
# File 'lib/config_to_env.rb', line 30 def self.flat_hash?(hash) hash.collect do |k,v| return false if !ConfigToEnv.is_value?(v) end end |
.flatten_hash(hash) ⇒ Object
Take a hash, and flatten it down to a simple key/value pair hash
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/config_to_env.rb', line 6 def self.flatten_hash(hash) if ConfigToEnv.flat_hash?(hash) return hash else # Perform single level flatten processed_hash = {} hash.each do |k,v| if ConfigToEnv.is_value?(v) processed_hash[k] = v else v.each do |l,w| processed_hash[k + '_' + l] = w end end end return ConfigToEnv.flatten_hash(processed_hash) end end |
.is_value?(node) ⇒ Boolean
26 27 28 |
# File 'lib/config_to_env.rb', line 26 def self.is_value?(node) !node.respond_to?(:each) end |