lib/active_remote/attributes.rb in active_remote-3.3.3 vs lib/active_remote/attributes.rb in active_remote-5.0.0.pre
- old
+ new
@@ -66,11 +66,11 @@
end
# Write an attribute to the attributes hash
#
def attribute=(name, value)
- @attributes[name] = value
+ @attributes[name] = self.class.attributes[name].from_user(value)
end
def attribute_method?(attr_name)
# Check if @attributes is defined because dangerous_attribute? method
# can check allocate.respond_to? before actaully calling initialize
@@ -86,13 +86,13 @@
# attributes class method.
#
# @example Define an attribute.
# attribute :name
#
- def attribute(name, options={})
- if dangerous_attribute_method_name = dangerous_attribute?(name)
- raise ::ActiveRemote::DangerousAttributeError, %{an attribute method named "#{dangerous_attribute_method_name}" would conflict with an existing method}
+ def attribute(name, options = {})
+ if (dangerous_attribute_method_name = dangerous_attribute?(name))
+ raise ::ActiveRemote::DangerousAttributeError, %(an attribute method named "#{dangerous_attribute_method_name}" would conflict with an existing method)
else
attribute!(name, options)
end
end
@@ -105,11 +105,11 @@
# {DangerousAttributeError}, but .attribute! will not.
#
# @example Define a dangerous attribute.
# attribute! :timeout
#
- def attribute!(name, options={})
+ def attribute!(name, options = {})
::ActiveRemote::AttributeDefinition.new(name, options).tap do |attribute_definition|
attribute_name = attribute_definition.name.to_s
# Force active model to generate attribute methods
remove_instance_variable("@attribute_methods_generated") if instance_variable_defined?("@attribute_methods_generated")
define_attribute_methods([attribute_definition.name]) unless attribute_names.include?(attribute_name)
@@ -162,10 +162,10 @@
# @example Inspect the model's definition.
# Person.inspect
#
def inspect
inspected_attributes = attribute_names.sort
- attributes_list = "(#{inspected_attributes.join(", ")})" unless inspected_attributes.empty?
+ attributes_list = "(#{inspected_attributes.join(', ')})" unless inspected_attributes.empty?
"#{name}#{attributes_list}"
end
protected