Skip to content

Commit

Permalink
Update creator.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
rudibroekhuizen committed Mar 15, 2016
1 parent 2ffd0ee commit c32a98c
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions ruby/creator.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
#!/usr/bin/env ruby
require 'pp'
require 'yaml'
require 'erb'

hash = YAML::load(File.open(ARGV[0]).read)
template = open('template.erb', 'r') {|f| f.read}
puts ERB.new(template, 0, '<>').result

def flatten_hash(my_hash, parent=[])
my_hash.flat_map do |key, value|
case value
when Hash then flatten_hash( value, parent+[key] )
else line = [(parent+[key]).join('')]
out = "#{line}"
out = out[2..-3]
print "$config#{out} = #{value};""\n"
end
end
end

flatten_hash(hash)

0 comments on commit c32a98c

Please sign in to comment.