Module: KnifeTopo::ViaCookbookPrint
- Included in:
- ViaCookbookProcessor
- Defined in:
- lib/chef/knife/topo/processor/via_cookbook_print.rb
Overview
Prints attribute file contents to string
Instance Method Summary collapse
- #cookbook_contents ⇒ Object
- #copyright ⇒ Object
- #print_attr(contents, lhs, value1) ⇒ Object
- #print_attr_header(contents, cookbook_name, filename) ⇒ Object
- #print_attrs(contents, attrs, indent = 0) ⇒ Object
- #print_attrs_for_node(contents, n) ⇒ Object
- #print_node_name_attr_header(contents, node_name) ⇒ Object
- #print_node_type_attr_header(contents, node_type) ⇒ Object
Instance Method Details
#cookbook_contents ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'lib/chef/knife/topo/processor/via_cookbook_print.rb', line 83 def cookbook_contents contents = '' print_attr_header(contents, @cookbook, @filename) print_attrs(contents, @topo['attributes']) @topo.nodes.each do |n| print_attrs_for_node(contents, n) end contents end |
#copyright ⇒ Object
93 94 95 |
# File 'lib/chef/knife/topo/processor/via_cookbook_print.rb', line 93 def copyright Chef::Config.copyright || @cmd.config['copyright'] end |
#print_attr(contents, lhs, value1) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/chef/knife/topo/processor/via_cookbook_print.rb', line 40 def print_attr(contents, lhs, value1) if value1.is_a?(Hash) value1.each do |key, value2| print_attr(contents, "#{lhs}['#{key}']", value2) end else ruby_str = value1.nil? ? 'nil' : Chef::JSONCompat.to_json(value1) contents << "#{lhs} = #{ruby_str}\n" end end |
#print_attr_header(contents, cookbook_name, filename) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/chef/knife/topo/processor/via_cookbook_print.rb', line 23 def print_attr_header(contents, cookbook_name, filename) copyright = @config['cookbook_copyright'] contents << " # # THIS FILE IS GENERATED BY KNIFE TOPO - MANUAL CHANGES WILL BE OVERWRITTEN # # Cookbook Name:: #{cookbook_name} # Attribute File:: #{filename} # " return unless copyright contents << " # Copyright (c) #{Time.now.year} #{copyright} # " end |
#print_attrs(contents, attrs, indent = 0) ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/chef/knife/topo/processor/via_cookbook_print.rb', line 51 def print_attrs(contents, attrs, indent = 0) return unless attrs KnifeTopo::PRIORITIES.each do |priority| next unless attrs[priority] lhs = '' indent.times { lhs << ' ' } lhs << priority print_attr(contents, lhs, attrs[priority]) end end |
#print_attrs_for_node(contents, n) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/chef/knife/topo/processor/via_cookbook_print.rb', line 62 def print_attrs_for_node(contents, n) if n['node_type'] print_node_type_attr_header(contents, n['node_type']) else print_node_name_attr_header(contents, n['name']) end print_attrs(contents, n, 2) contents << "end\n" end |
#print_node_name_attr_header(contents, node_name) ⇒ Object
78 79 80 81 |
# File 'lib/chef/knife/topo/processor/via_cookbook_print.rb', line 78 def print_node_name_attr_header(contents, node_name) contents << "# Attributes for node name #{node_name}\n" contents << "if node.name == '#{node_name}'\n" end |
#print_node_type_attr_header(contents, node_type) ⇒ Object
72 73 74 75 76 |
# File 'lib/chef/knife/topo/processor/via_cookbook_print.rb', line 72 def print_node_type_attr_header(contents, node_type) contents << "# Attributes for node type #{node_type}\n" contents << "if node['topo'] && node['topo']['node_type']" \ " == '#{node_type}'\n" end |