lib/active_remote/attributes.rb in active_remote-3.1.2 vs lib/active_remote/attributes.rb in active_remote-3.1.3
- old
+ new
@@ -112,10 +112,11 @@
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)
attributes[attribute_name] = attribute_definition
+ build_default_attributes_hash
end
end
# Returns an Array of attribute names as Strings
#
@@ -179,9 +180,17 @@
# Expand an attribute name into its generated methods names
#
def attribute_methods(name)
attribute_method_matchers.map { |matcher| matcher.method_name(name) }
+ end
+
+ def build_default_attributes_hash
+ @default_attributes_hash = Hash[attribute_names.map { |key| [key, nil] }]
+ end
+
+ def default_attributes_hash
+ @default_attributes_hash || {}
end
# Ruby inherited hook to assign superclass attributes to subclasses
#
def inherited(subclass)