diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2016-02-05 15:00:00 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2016-02-05 15:00:00 -0800 |
commit | 686113531d23f30e9973d659c456ae33eb9cff1f (patch) | |
tree | f225de7251a8b49b8d183dd168bab0a0addbe23f /lib/chef/node | |
parent | d1cf34b059a16a81e0fc48de52ba29863bb41fe6 (diff) | |
download | chef-686113531d23f30e9973d659c456ae33eb9cff1f.tar.gz |
autofixing whitespace cops
4174 Style/SpaceInsideHashLiteralBraces
1860 Style/SpaceAroundOperators
1336 Style/SpaceInsideBlockBraces
1292 Style/AlignHash
997 Style/SpaceAfterComma
860 Style/SpaceAroundEqualsInParameterDefault
310 Style/EmptyLines
294 Style/IndentationConsistency
267 Style/TrailingWhitespace
238 Style/ExtraSpacing
212 Style/SpaceBeforeBlockBraces
166 Style/MultilineOperationIndentation
144 Style/TrailingBlankLines
120 Style/EmptyLineBetweenDefs
101 Style/IndentationWidth
82 Style/SpaceAroundBlockParameters
40 Style/EmptyLinesAroundMethodBody
29 Style/EmptyLinesAroundAccessModifier
1 Style/RescueEnsureAlignment
Diffstat (limited to 'lib/chef/node')
-rw-r--r-- | lib/chef/node/attribute.rb | 558 | ||||
-rw-r--r-- | lib/chef/node/attribute_collections.rb | 6 | ||||
-rw-r--r-- | lib/chef/node/immutable_collections.rb | 2 |
3 files changed, 283 insertions, 283 deletions
diff --git a/lib/chef/node/attribute.rb b/lib/chef/node/attribute.rb index 0ed4a9360a..13ce75455f 100644 --- a/lib/chef/node/attribute.rb +++ b/lib/chef/node/attribute.rb @@ -144,34 +144,34 @@ class Chef end # return the cookbook level default attribute component - attr_reader :default + attr_reader :default # return the role level default attribute component - attr_reader :role_default + attr_reader :role_default # return the environment level default attribute component - attr_reader :env_default + attr_reader :env_default # return the force_default level attribute component - attr_reader :force_default + attr_reader :force_default # return the "normal" level attribute component - attr_reader :normal + attr_reader :normal # return the cookbook level override attribute component - attr_reader :override + attr_reader :override # return the role level override attribute component - attr_reader :role_override + attr_reader :role_override # return the enviroment level override attribute component - attr_reader :env_override + attr_reader :env_override # return the force override level attribute component - attr_reader :force_override + attr_reader :force_override # return the automatic level attribute component - attr_reader :automatic + attr_reader :automatic # This is used to track the top level key as we descend through method chaining into # a precedence level (e.g. node.default['foo']['bar']['baz']= results in 'foo' here). We @@ -179,36 +179,36 @@ class Chef # that we can invalidate the whole top-level deep merge cache for the top-level key. It is # the responsibility of the accessor on the Chef::Node object to reset this to nil, and then # the first VividMash#[] call can ||= and set this to the first key we encounter. - attr_accessor :top_level_breadcrumb + attr_accessor :top_level_breadcrumb # Cache of deep merged values by top-level key. This is a simple hash which has keys that are the # top-level keys of the node object, and we save the computed deep-merge for that key here. There is # no cache of subtrees. - attr_accessor :deep_merge_cache + attr_accessor :deep_merge_cache - def initialize(normal, default, override, automatic) - @set_unless_present = false + def initialize(normal, default, override, automatic) + @set_unless_present = false - @default = VividMash.new(self, default) - @env_default = VividMash.new(self, {}) - @role_default = VividMash.new(self, {}) - @force_default = VividMash.new(self, {}) + @default = VividMash.new(self, default) + @env_default = VividMash.new(self, {}) + @role_default = VividMash.new(self, {}) + @force_default = VividMash.new(self, {}) - @normal = VividMash.new(self, normal) + @normal = VividMash.new(self, normal) - @override = VividMash.new(self, override) - @role_override = VividMash.new(self, {}) - @env_override = VividMash.new(self, {}) - @force_override = VividMash.new(self, {}) + @override = VividMash.new(self, override) + @role_override = VividMash.new(self, {}) + @env_override = VividMash.new(self, {}) + @force_override = VividMash.new(self, {}) - @automatic = VividMash.new(self, automatic) + @automatic = VividMash.new(self, automatic) - @merged_attributes = nil - @combined_override = nil - @combined_default = nil - @top_level_breadcrumb = nil - @deep_merge_cache = {} - end + @merged_attributes = nil + @combined_override = nil + @combined_default = nil + @top_level_breadcrumb = nil + @deep_merge_cache = {} + end # Debug what's going on with an attribute. +args+ is a path spec to the # attribute you're interested in. For example, to debug where the value @@ -221,195 +221,195 @@ class Chef # the component, such as role default, normal, etc. and value is the # attribute value set at that precedence level. If there is no value at # that precedence level, +value+ will be the symbol +:not_present+. - def debug_value(*args) - components = COMPONENTS.map do |component| - ivar = instance_variable_get(component) - value = args.inject(ivar) do |so_far, key| - if so_far == :not_present - :not_present - elsif so_far.has_key?(key) - so_far[key] - else - :not_present - end - end - [component.to_s.sub(/^@/,""), value] - end - [["set_unless_enabled?", @set_unless_present]] + components - end + def debug_value(*args) + components = COMPONENTS.map do |component| + ivar = instance_variable_get(component) + value = args.inject(ivar) do |so_far, key| + if so_far == :not_present + :not_present + elsif so_far.has_key?(key) + so_far[key] + else + :not_present + end + end + [component.to_s.sub(/^@/, ""), value] + end + [["set_unless_enabled?", @set_unless_present]] + components + end # Enables or disables `||=`-like attribute setting. See, e.g., Node#set_unless - def set_unless_value_present=(setting) - @set_unless_present = setting - end + def set_unless_value_present=(setting) + @set_unless_present = setting + end # Invalidate a key in the deep_merge_cache. If called with nil, or no arg, this will invalidate # the entire deep_merge cache. In the case of the user doing node.default['foo']['bar']['baz']= # that eventually results in a call to reset_cache('foo') here. A node.default=hash_thing call # must invalidate the entire cache and re-deep-merge the entire node object. - def reset_cache(path = nil) - if path.nil? - @deep_merge_cache = {} - else - deep_merge_cache.delete(path.to_s) - end - end + def reset_cache(path = nil) + if path.nil? + @deep_merge_cache = {} + else + deep_merge_cache.delete(path.to_s) + end + end - alias :reset :reset_cache + alias :reset :reset_cache # Set the cookbook level default attribute component to +new_data+. - def default=(new_data) - reset - @default = VividMash.new(self, new_data) - end + def default=(new_data) + reset + @default = VividMash.new(self, new_data) + end # Set the role level default attribute component to +new_data+ - def role_default=(new_data) - reset - @role_default = VividMash.new(self, new_data) - end + def role_default=(new_data) + reset + @role_default = VividMash.new(self, new_data) + end # Set the environment level default attribute component to +new_data+ - def env_default=(new_data) - reset - @env_default = VividMash.new(self, new_data) - end + def env_default=(new_data) + reset + @env_default = VividMash.new(self, new_data) + end # Set the force_default (+default!+) level attributes to +new_data+ - def force_default=(new_data) - reset - @force_default = VividMash.new(self, new_data) - end + def force_default=(new_data) + reset + @force_default = VividMash.new(self, new_data) + end # Set the normal level attribute component to +new_data+ - def normal=(new_data) - reset - @normal = VividMash.new(self, new_data) - end + def normal=(new_data) + reset + @normal = VividMash.new(self, new_data) + end # Set the cookbook level override attribute component to +new_data+ - def override=(new_data) - reset - @override = VividMash.new(self, new_data) - end + def override=(new_data) + reset + @override = VividMash.new(self, new_data) + end # Set the role level override attribute component to +new_data+ - def role_override=(new_data) - reset - @role_override = VividMash.new(self, new_data) - end + def role_override=(new_data) + reset + @role_override = VividMash.new(self, new_data) + end # Set the environment level override attribute component to +new_data+ - def env_override=(new_data) - reset - @env_override = VividMash.new(self, new_data) - end + def env_override=(new_data) + reset + @env_override = VividMash.new(self, new_data) + end - def force_override=(new_data) - reset - @force_override = VividMash.new(self, new_data) - end + def force_override=(new_data) + reset + @force_override = VividMash.new(self, new_data) + end - def automatic=(new_data) - reset - @automatic = VividMash.new(self, new_data) - end + def automatic=(new_data) + reset + @automatic = VividMash.new(self, new_data) + end # # Deleting attributes # # clears attributes from all precedence levels - def rm(*args) - reset(args[0]) - # just easier to compute our retval, rather than collect+merge sub-retvals - ret = args.inject(merged_attributes) do |attr, arg| - if attr.nil? || !attr.respond_to?(:[]) - nil - else - begin - attr[arg] - rescue TypeError - raise TypeError, "Wrong type in index of attribute (did you use a Hash index on an Array?)" - end - end - end - rm_default(*args) - rm_normal(*args) - rm_override(*args) - ret - end + def rm(*args) + reset(args[0]) + # just easier to compute our retval, rather than collect+merge sub-retvals + ret = args.inject(merged_attributes) do |attr, arg| + if attr.nil? || !attr.respond_to?(:[]) + nil + else + begin + attr[arg] + rescue TypeError + raise TypeError, "Wrong type in index of attribute (did you use a Hash index on an Array?)" + end + end + end + rm_default(*args) + rm_normal(*args) + rm_override(*args) + ret + end # does <level>['foo']['bar'].delete('baz') - def remove_from_precedence_level(level, *args, key) - multimash = level.element(*args) - multimash.nil? ? nil : multimash.delete(key) - end + def remove_from_precedence_level(level, *args, key) + multimash = level.element(*args) + multimash.nil? ? nil : multimash.delete(key) + end - private :remove_from_precedence_level + private :remove_from_precedence_level # clears attributes from all default precedence levels # # equivalent to: force_default!['foo']['bar'].delete('baz') - def rm_default(*args) - reset(args[0]) - remove_from_precedence_level(force_default!(autovivify: false), *args) - end + def rm_default(*args) + reset(args[0]) + remove_from_precedence_level(force_default!(autovivify: false), *args) + end # clears attributes from normal precedence # # equivalent to: normal!['foo']['bar'].delete('baz') - def rm_normal(*args) - reset(args[0]) - remove_from_precedence_level(normal!(autovivify: false), *args) - end + def rm_normal(*args) + reset(args[0]) + remove_from_precedence_level(normal!(autovivify: false), *args) + end # clears attributes from all override precedence levels # # equivalent to: force_override!['foo']['bar'].delete('baz') - def rm_override(*args) - reset(args[0]) - remove_from_precedence_level(force_override!(autovivify: false), *args) - end + def rm_override(*args) + reset(args[0]) + remove_from_precedence_level(force_override!(autovivify: false), *args) + end # # Replacing attributes without merging # # sets default attributes without merging - def default!(opts={}) - # FIXME: do not flush whole cache - reset - MultiMash.new(self, @default, [], opts) - end + def default!(opts = {}) + # FIXME: do not flush whole cache + reset + MultiMash.new(self, @default, [], opts) + end # sets normal attributes without merging - def normal!(opts={}) - # FIXME: do not flush whole cache - reset - MultiMash.new(self, @normal, [], opts) - end + def normal!(opts = {}) + # FIXME: do not flush whole cache + reset + MultiMash.new(self, @normal, [], opts) + end # sets override attributes without merging - def override!(opts={}) - # FIXME: do not flush whole cache - reset - MultiMash.new(self, @override, [], opts) - end + def override!(opts = {}) + # FIXME: do not flush whole cache + reset + MultiMash.new(self, @override, [], opts) + end # clears from all default precedence levels and then sets force_default - def force_default!(opts={}) - # FIXME: do not flush whole cache - reset - MultiMash.new(self, @force_default, [@default, @env_default, @role_default], opts) - end + def force_default!(opts = {}) + # FIXME: do not flush whole cache + reset + MultiMash.new(self, @force_default, [@default, @env_default, @role_default], opts) + end # clears from all override precedence levels and then sets force_override - def force_override!(opts={}) - # FIXME: do not flush whole cache - reset - MultiMash.new(self, @force_override, [@override, @env_override, @role_override], opts) - end + def force_override!(opts = {}) + # FIXME: do not flush whole cache + reset + MultiMash.new(self, @force_override, [@override, @env_override, @role_override], opts) + end # # Accessing merged attributes. @@ -419,75 +419,75 @@ class Chef # all of node['foo'] even if the user only requires node['foo']['bar']['baz']. # - def merged_attributes(*path) - # immutablize( - merge_all(path) - # ) - end - - def combined_override(*path) - immutablize(merge_overrides(path)) - end - - def combined_default(*path) - immutablize(merge_defaults(path)) - end - - def [](key) - if deep_merge_cache.has_key?(key.to_s) - # return the cache of the deep merged values by top-level key - deep_merge_cache[key.to_s] - else - # save all the work of computing node[key] - deep_merge_cache[key.to_s] = merged_attributes(key) - end - end - - def []=(key, value) - raise Exceptions::ImmutableAttributeModification - end - - def has_key?(key) - COMPONENTS.any? do |component_ivar| - instance_variable_get(component_ivar).has_key?(key) - end - end - - alias :attribute? :has_key? - alias :member? :has_key? - alias :include? :has_key? - alias :key? :has_key? - - alias :each_attribute :each - - def method_missing(symbol, *args) - if args.empty? - if key?(symbol) - self[symbol] - else - raise NoMethodError, "Undefined method or attribute `#{symbol}' on `node'" - end - elsif symbol.to_s =~ /=$/ - key_to_set = symbol.to_s[/^(.+)=$/, 1] - self[key_to_set] = (args.length == 1 ? args[0] : args) - else - raise NoMethodError, "Undefined node attribute or method `#{symbol}' on `node'" - end - end - - def to_s - merged_attributes.to_s - end - - def inspect - "#<#{self.class} " << (COMPONENTS + [:@merged_attributes, :@properties]).map{|iv| - "#{iv}=#{instance_variable_get(iv).inspect}" - }.join(", ") << ">" - end - - def set_unless? - @set_unless_present - end + def merged_attributes(*path) + # immutablize( + merge_all(path) + # ) + end + + def combined_override(*path) + immutablize(merge_overrides(path)) + end + + def combined_default(*path) + immutablize(merge_defaults(path)) + end + + def [](key) + if deep_merge_cache.has_key?(key.to_s) + # return the cache of the deep merged values by top-level key + deep_merge_cache[key.to_s] + else + # save all the work of computing node[key] + deep_merge_cache[key.to_s] = merged_attributes(key) + end + end + + def []=(key, value) + raise Exceptions::ImmutableAttributeModification + end + + def has_key?(key) + COMPONENTS.any? do |component_ivar| + instance_variable_get(component_ivar).has_key?(key) + end + end + + alias :attribute? :has_key? + alias :member? :has_key? + alias :include? :has_key? + alias :key? :has_key? + + alias :each_attribute :each + + def method_missing(symbol, *args) + if args.empty? + if key?(symbol) + self[symbol] + else + raise NoMethodError, "Undefined method or attribute `#{symbol}' on `node'" + end + elsif symbol.to_s =~ /=$/ + key_to_set = symbol.to_s[/^(.+)=$/, 1] + self[key_to_set] = (args.length == 1 ? args[0] : args) + else + raise NoMethodError, "Undefined node attribute or method `#{symbol}' on `node'" + end + end + + def to_s + merged_attributes.to_s + end + + def inspect + "#<#{self.class} " << (COMPONENTS + [:@merged_attributes, :@properties]).map{|iv| + "#{iv}=#{instance_variable_get(iv).inspect}" + }.join(", ") << ">" + end + + def set_unless? + @set_unless_present + end private @@ -501,32 +501,32 @@ class Chef # raise any TypeError if it attempts to apply a hash key to an Integer/String/TrueClass, and just returns # nil in that case. # - def apply_path(component, path) - path ||= [] - path.inject(component) do |val, path_arg| - if val.respond_to?(:[]) - # Have an Array-like or Hash-like thing - if !val.respond_to?(:has_key?) - # Have an Array-like thing - val[path_arg] - elsif val.has_key?(path_arg) - # Hash-like thing (must check has_key? first to protect against Autovivification) - val[path_arg] - else - nil - end - else - nil - end - end - end + def apply_path(component, path) + path ||= [] + path.inject(component) do |val, path_arg| + if val.respond_to?(:[]) + # Have an Array-like or Hash-like thing + if !val.respond_to?(:has_key?) + # Have an Array-like thing + val[path_arg] + elsif val.has_key?(path_arg) + # Hash-like thing (must check has_key? first to protect against Autovivification) + val[path_arg] + else + nil + end + else + nil + end + end + end # For elements like Fixnums, true, nil... - def safe_dup(e) - e.dup - rescue TypeError - e - end + def safe_dup(e) + e.dup + rescue TypeError + e + end # Deep merge all attribute levels using hash-only merging between different precidence # levels (so override arrays completely replace arrays set at any default level). @@ -535,24 +535,24 @@ class Chef # # @param path [Array] Array of args to method chain to descend into the node object # @return [attr] Deep Merged values (may be VividMash, Hash, Array, etc) from the node object - def merge_all(path) - components = [ - merge_defaults(path), - apply_path(@normal, path), - merge_overrides(path), - apply_path(@automatic, path), - ] - - components.map! do |component| - safe_dup(component) - end + def merge_all(path) + components = [ + merge_defaults(path), + apply_path(@normal, path), + merge_overrides(path), + apply_path(@automatic, path), + ] - return nil if components.compact.empty? + components.map! do |component| + safe_dup(component) + end - components.inject(ImmutableMash.new({})) do |merged, component| - Chef::Mixin::DeepMerge.hash_only_merge!(merged, component) - end - end + return nil if components.compact.empty? + + components.inject(ImmutableMash.new({})) do |merged, component| + Chef::Mixin::DeepMerge.hash_only_merge!(merged, component) + end + end # Deep merge the default attribute levels with array merging. # @@ -560,12 +560,12 @@ class Chef # # @param path [Array] Array of args to method chain to descend into the node object # @return [attr] Deep Merged values (may be VividMash, Hash, Array, etc) from the node object - def merge_defaults(path) - DEFAULT_COMPONENTS.inject(nil) do |merged, component_ivar| - component_value = apply_path(instance_variable_get(component_ivar), path) - Chef::Mixin::DeepMerge.deep_merge(component_value, merged) - end - end + def merge_defaults(path) + DEFAULT_COMPONENTS.inject(nil) do |merged, component_ivar| + component_value = apply_path(instance_variable_get(component_ivar), path) + Chef::Mixin::DeepMerge.deep_merge(component_value, merged) + end + end # Deep merge the override attribute levels with array merging. # @@ -573,12 +573,12 @@ class Chef # # @param path [Array] Array of args to method chain to descend into the node object # @return [attr] Deep Merged values (may be VividMash, Hash, Array, etc) from the node object - def merge_overrides(path) - OVERRIDE_COMPONENTS.inject(nil) do |merged, component_ivar| - component_value = apply_path(instance_variable_get(component_ivar), path) - Chef::Mixin::DeepMerge.deep_merge(component_value, merged) - end - end + def merge_overrides(path) + OVERRIDE_COMPONENTS.inject(nil) do |merged, component_ivar| + component_value = apply_path(instance_variable_get(component_ivar), path) + Chef::Mixin::DeepMerge.deep_merge(component_value, merged) + end + end end diff --git a/lib/chef/node/attribute_collections.rb b/lib/chef/node/attribute_collections.rb index c52582a520..68f3a69756 100644 --- a/lib/chef/node/attribute_collections.rb +++ b/lib/chef/node/attribute_collections.rb @@ -82,7 +82,7 @@ class Chef end def dup - Array.new(map {|e| safe_dup(e)}) + Array.new(map { |e| safe_dup(e) }) end end @@ -130,7 +130,7 @@ class Chef end end - def initialize(root, data={}) + def initialize(root, data = {}) @root = root super(data) end @@ -241,7 +241,7 @@ class Chef # Initialize with an array of mashes. For the delete return value to work # properly the mashes must come from the same attribute level (i.e. all # override or all default, but not a mix of both). - def initialize(root, primary_mash, mashes, opts={}) + def initialize(root, primary_mash, mashes, opts = {}) @root = root @primary_mash = primary_mash @mashes = mashes diff --git a/lib/chef/node/immutable_collections.rb b/lib/chef/node/immutable_collections.rb index c092c8cacc..b5fd86fa72 100644 --- a/lib/chef/node/immutable_collections.rb +++ b/lib/chef/node/immutable_collections.rb @@ -88,7 +88,7 @@ class Chef end def dup - Array.new(map {|e| safe_dup(e)}) + Array.new(map { |e| safe_dup(e) }) end def to_a |