diff options
Diffstat (limited to 'lib/chef/property.rb')
-rw-r--r-- | lib/chef/property.rb | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/lib/chef/property.rb b/lib/chef/property.rb index d7ef19ee3d..8198dd6700 100644 --- a/lib/chef/property.rb +++ b/lib/chef/property.rb @@ -87,12 +87,11 @@ class Chef # is fully initialized. # def initialize(**options) - options.each { |k,v| options[k.to_sym] = v; options.delete(k) if k.is_a?(String) } + options.each { |k, v| options[k.to_sym] = v; options.delete(k) if k.is_a?(String) } @options = options options[:name] = options[:name].to_sym if options[:name] options[:instance_variable_name] = options[:instance_variable_name].to_sym if options[:instance_variable_name] - # Replace name_attribute with name_property if options.has_key?(:name_attribute) # If we have both name_attribute and name_property and they differ, raise an error @@ -100,7 +99,7 @@ class Chef raise ArgumentError, "Cannot specify both name_property and name_attribute together on property #{self}." end # replace name_property with name_attribute in place - options = Hash[options.map { |k,v| k == :name_attribute ? [ :name_property, v ] : [ k,v ] }] + options = Hash[options.map { |k, v| k == :name_attribute ? [ :name_property, v ] : [ k, v ] }] @options = options end @@ -233,8 +232,8 @@ class Chef # @return [Hash<Symbol,Object>] # def validation_options - @validation_options ||= options.reject { |k,v| - [:declared_in,:name,:instance_variable_name,:desired_state,:identity,:default,:name_property,:coerce,:required].include?(k) + @validation_options ||= options.reject { |k, v| + [:declared_in, :name, :instance_variable_name, :desired_state, :identity, :default, :name_property, :coerce, :required].include?(k) } end @@ -258,7 +257,7 @@ class Chef # will be returned without running, validating or coercing. If it is a # `get`, the non-lazy, coerced, validated value will always be returned. # - def call(resource, value=NOT_PASSED) + def call(resource, value = NOT_PASSED) if value == NOT_PASSED return get(resource) end @@ -342,7 +341,7 @@ class Chef resource.enclosing_provider && resource.enclosing_provider.new_resource && resource.enclosing_provider.new_resource.respond_to?(name) - Chef::Log.warn("#{Chef::Log.caller_location}: property #{name} is declared in both #{resource} and #{resource.enclosing_provider}. Use new_resource.#{name} instead. At #{Chef::Log.caller_location}") + Chef::Log.warn("#{Chef::Log.caller_location}: property #{name} is declared in both #{resource} and #{resource.enclosing_provider}. Use new_resource.#{name} instead. At #{Chef::Log.caller_location}") end if has_default? @@ -489,7 +488,7 @@ class Chef if modified_options.has_key?(:name_property) || modified_options.has_key?(:name_attribute) || modified_options.has_key?(:default) - options = options.reject { |k,v| k == :name_attribute || k == :name_property || k == :default } + options = options.reject { |k, v| k == :name_attribute || k == :name_property || k == :default } end self.class.new(options.merge(modified_options)) end @@ -506,7 +505,7 @@ class Chef # We prefer this form because the property name won't show up in the # stack trace if you use `define_method`. - declared_in.class_eval <<-EOM, __FILE__, __LINE__+1 + declared_in.class_eval <<-EOM, __FILE__, __LINE__ + 1 def #{name}(value=NOT_PASSED) raise "Property #{name} of \#{self} cannot be passed a block! If you meant to create a resource named #{name} instead, you'll need to first rename the property." if block_given? self.class.properties[#{name.inspect}].call(self, value) @@ -518,7 +517,7 @@ class Chef EOM rescue SyntaxError # If the name is not a valid ruby name, we use define_method. - declared_in.define_method(name) do |value=NOT_PASSED, &block| + declared_in.define_method(name) do |value = NOT_PASSED, &block| raise "Property #{name} of #{self} cannot be passed a block! If you meant to create a resource named #{name} instead, you'll need to first rename the property." if block self.class.properties[name].call(self, value) end @@ -577,7 +576,7 @@ class Chef # @api private def explicitly_accepts_nil?(resource) options.has_key?(:coerce) || - (options.has_key?(:is) && resource.send(:_pv_is, { name => nil }, name, options[:is], raise_error: false)) + (options.has_key?(:is) && resource.send(:_pv_is, { name => nil }, name, options[:is], raise_error: false)) end def get_value(resource) |