class Chef::Knife::Scrub::AttributeExtractor::Base
Public Class Methods
new(node, precedence)
click to toggle source
# File lib/chef/knife/scrub/attribute_extractor.rb, line 25 def initialize(node, precedence) @node = node @precedence = precedence end
Public Instance Methods
delete(key)
click to toggle source
# File lib/chef/knife/scrub/attribute_extractor.rb, line 38 def delete(key) raise NotImplementedError end
fetch(key)
click to toggle source
# File lib/chef/knife/scrub/attribute_extractor.rb, line 34 def fetch(key) raise NotImplementedError end
has_key?(key)
click to toggle source
# File lib/chef/knife/scrub/attribute_extractor.rb, line 30 def has_key?(key) raise NotImplementedError end
Protected Instance Methods
attributes()
click to toggle source
# File lib/chef/knife/scrub/attribute_extractor.rb, line 44 def attributes @node.send(@precedence) end
extract(data, nested_value_spec)
click to toggle source
# File lib/chef/knife/scrub/attribute_extractor.rb, line 48 def extract(data, nested_value_spec) spec = nested_value_spec.split(".") key = spec.pop spec.each do |attr| if data.nil? nil # don't get no method error on nil elsif data.respond_to?(attr.to_sym) data = data.send(attr.to_sym) elsif data.respond_to?(:[]) data = data[attr] else data = begin data.send(attr.to_sym) rescue NoMethodError nil end end end [data, key] end