Class: Fhcap::DummyNode
- Inherits:
-
Chef::Node
- Object
- Chef::Node
- Fhcap::DummyNode
- Defined in:
- lib/fhcap/dummy_node.rb
Instance Attribute Summary collapse
-
#included_recipe_attributes ⇒ Object
Returns the value of attribute included_recipe_attributes.
Instance Method Summary collapse
- #from_file(filename) ⇒ Object
- #get_attributes(hash, attrs = nil, keys = nil) ⇒ Object
- #ignore_key?(key) ⇒ Boolean
- #include_attribute(recipe) ⇒ Object
-
#initialize ⇒ DummyNode
constructor
A new instance of DummyNode.
- #metadata_attributes ⇒ Object
- #parse_value(value) ⇒ Object
Constructor Details
#initialize ⇒ DummyNode
Returns a new instance of DummyNode.
9 10 11 12 |
# File 'lib/fhcap/dummy_node.rb', line 9 def initialize super @included_recipe_attributes = [] end |
Instance Attribute Details
#included_recipe_attributes ⇒ Object
Returns the value of attribute included_recipe_attributes.
7 8 9 |
# File 'lib/fhcap/dummy_node.rb', line 7 def included_recipe_attributes @included_recipe_attributes end |
Instance Method Details
#from_file(filename) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/fhcap/dummy_node.rb', line 18 def from_file(filename) if File.exists?(filename) && File.readable?(filename) #Convert any references to node['blah'] to a string so instance_eval doesn't try to evaluate it text = "" ignore_lines = false File.open(filename).each_line do |line| key, value = line.split(/ = /, 2) if key && value ignore_lines = false if ignore_key? key value = "\"Ignored\"" ignore_lines = true else value.gsub!(/node(\[['a-zA-Z0-9_-]*\])+/, '"\&"') value.gsub!(/node.chef_environment/, '"\&"') if value =~ /\.* \| "node\[/ value.gsub!(/"/, '') value = "\"#{value.chomp}\"\n" end end line = "#{key} = #{value}" end text += line unless ignore_lines end self.instance_eval(text, filename, 1) else raise IOError, "Cannot open or read #{filename}!" end end |
#get_attributes(hash, attrs = nil, keys = nil) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/fhcap/dummy_node.rb', line 56 def get_attributes(hash, attrs=nil, keys=nil) keys ||= [] attrs ||= {} hash.sort.each() do |k, v| keys << k.to_s if v.is_a? Hash self.get_attributes(v, attrs, keys) else attrs[keys.join("/")] = {:default => parse_value(v)} end keys.pop end attrs end |
#ignore_key?(key) ⇒ Boolean
48 49 50 |
# File 'lib/fhcap/dummy_node.rb', line 48 def ignore_key?(key) key =~ /\['cron_jobs'\]/ end |
#include_attribute(recipe) ⇒ Object
14 15 16 |
# File 'lib/fhcap/dummy_node.rb', line 14 def include_attribute(recipe) @included_recipe_attributes << recipe end |
#metadata_attributes ⇒ Object
52 53 54 |
# File 'lib/fhcap/dummy_node.rb', line 52 def self.get_attributes(node.default_attrs) end |
#parse_value(value) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/fhcap/dummy_node.rb', line 71 def parse_value(value) if value.is_a? Array value else value.to_s end end |