lib/puppet/resource_api/glue.rb in puppet-resource_api-1.6.4 vs lib/puppet/resource_api/glue.rb in puppet-resource_api-1.6.5

- old
+ new

@@ -39,11 +39,37 @@ def to_hierayaml attributes = Hash[filtered_keys.map { |k| [k.to_s, values[k]] }] YAML.dump('type' => { title => attributes }).split("\n").drop(2).join("\n") + "\n" end + def to_hash + values + end + + def to_json(*) + attrs = filtered_keys.map { |k| [k.to_s, values[k]] unless values[k].nil? } + attributes = Hash[*attrs.compact.flatten] + resource = { title => attributes } + resource.to_json + end + # attribute names that are not title or namevars def filtered_keys values.keys.reject { |k| k == :title || !attr_def[k] || (attr_def[k][:behaviour] == :namevar && @namevars.size == 1) } + end + end + + # this hash allows key-value based ordering comparisons between instances of this and instances of this and other classes + # this is required for `lib/puppet/indirector/resource/ral.rb`'s `search` method which expects all titles to be comparable + class MonkeyHash < Hash + def <=>(other) + result = self.class.name <=> other.class.name + if result.zero? + result = keys.sort <=> other.keys.sort + end + if result.zero? + result = keys.sort.map { |k| self[k] } <=> other.keys.sort.map { |k| other[k] } + end + result end end end