Sha256: b1f7be320ffacaacccac9a885d9df81edf8a98aaf0b43e4f23f277c005eda215
Contents?: true
Size: 887 Bytes
Versions: 1
Compression:
Stored size: 887 Bytes
Contents
module ConfigVolumizer # Converts a {Hash} into a flattened {Hash} as a template for volumizing your configs module Generator class << self # Generates a flattened config out of a data hash # # See Readme for an example # # @param [Hash] data # @return [Hash] def generate(data) data.inject({}) do |result, (key, value)| process_item(result, key, value) result end end def process_item(result, prefix, value) case value when Array value.each_with_index do |item, index| process_item(result, "#{prefix}[#{index}]", item) end when Hash value.each do |key, item| process_item(result, "#{prefix}.#{key}", item) end else result[prefix] = value end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
config_volumizer-0.2.0 | lib/config_volumizer/generator.rb |