lib/virtus/instance_methods.rb in virtus-0.3.0 vs lib/virtus/instance_methods.rb in virtus-0.4.0
- old
+ new
@@ -9,12 +9,12 @@
# the attributes hash to be set
#
# @return [undefined]
#
# @api private
- def initialize(attribute_values = {})
- self.attributes = attribute_values
+ def initialize(attributes = nil)
+ self.attributes = attributes if attributes
end
# Returns a value of the attribute with the given name
#
# @example
@@ -85,11 +85,11 @@
get_attributes(&:public_reader?)
end
# Mass-assign attribute values
#
- # Keys in the +attribute_values+ param can be symbols or strings.
+ # Keys in the +attributes+ param can be symbols or strings.
# All referenced Attribute writer methods *will* be called.
# Non-attribute setter methods on the receiver *will* be called.
#
# @example
# class User
@@ -100,18 +100,18 @@
# end
#
# user = User.new
# user.attributes = { :name => 'John', 'age' => 28 }
#
- # @param [#to_hash] attribute_values
+ # @param [#to_hash] attributes
# a hash of attribute names and values to set on the receiver
#
# @return [Hash]
#
# @api public
- def attributes=(attribute_values)
- set_attributes(attribute_values)
+ def attributes=(attributes)
+ set_attributes(attributes)
end
# Returns a hash of all publicly accessible attributes
#
# @example
@@ -151,11 +151,11 @@
# @see Virtus::InstanceMethods#attributes=
#
# @return [Hash]
#
# @api private
- def set_attributes(attribute_values)
- attribute_values.each do |name, value|
+ def set_attributes(attributes)
+ ::Hash.try_convert(attributes).each do |name, value|
set_attribute(name, value) if self.class.allowed_writer_methods.include?("#{name}=")
end
end
# Returns a value of the attribute with the given name