lib/knife/undev/converter.rb in knife-undev-0.0.4 vs lib/knife/undev/converter.rb in knife-undev-0.0.5
- old
+ new
@@ -7,10 +7,11 @@
class Converter
def initialize(filename, klass = 'role')
@filename = filename
@klass = klass
+ @comment_counter = 0
end
def to_yml
case @klass
when 'env'
@@ -22,10 +23,14 @@
def safe_delete(hash, key)
hash.delete(key) if hash[key].nil? || hash[key].empty?
end
+ def comment(hash, value='')
+ hash["#comment_#{@comment_counter+=1}"] = ""
+ end
+
def role_to_yml
r = Chef::Role.new
r.from_file(@filename)
hash = r.to_hash.dup
result_hash = Hash.new
@@ -33,12 +38,19 @@
hash.delete('json_class')
safe_delete(hash, 'override_attributes')
safe_delete(hash, 'run_list')
result_hash['name'] = hash.delete('name')
result_hash['description'] = hash.delete('description')
+ comment(result_hash)
result_hash['env_run_lists'] = hash.delete('env_run_lists')
- puts result_hash.merge(hash).to_yaml
+ comment(result_hash)
+ result_hash.merge(hash).to_yaml.each_line do |line|
+ puts '' if line.match /#comment_\d+/
+ next if line.match /#comment_\d+/
+ next if line == '---'
+ puts line
+ end
end
def env_to_yml
r = Chef::Environment.new
r.from_file(@filename)
@@ -47,10 +59,12 @@
hash.delete('json_class')
safe_delete(hash, 'override_attributes')
safe_delete(hash, 'default_attributes')
safe_delete(hash, 'cookbook_versions')
safe_delete(hash, 'description')
- puts hash.to_yaml
+ hash.to_yaml.each_line do |line|
+ next if line == '---'
+ end
end
end
end
end