lib/ripple/attribute_methods.rb in ripple-0.9.0.beta vs lib/ripple/attribute_methods.rb in ripple-0.9.0.beta2

- old
+ new

@@ -31,10 +31,12 @@ include Read include Write include Query include Dirty include ActiveModel::MassAssignmentSecurity + + attr_protected :key end module ClassMethods # @private def property(key, type, options={}) @@ -53,20 +55,20 @@ # A copy of the values of all attributes in the Document. The result # is not memoized, so use sparingly. This does not include associated objects, # nor embedded documents. # @return [Hash] all document attributes, by key def attributes - self.class.properties.values.inject({}) do |hash, prop| + self.class.properties.values.inject(@attributes.with_indifferent_access) do |hash, prop| hash[prop.key] = attribute(prop.key) hash - end.with_indifferent_access + end end # Mass assign the document's attributes. # @param [Hash] attrs the attributes to assign - def attributes=(attrs) + def attributes=(attrs, guard_protected_attrs = true) raise ArgumentError, t('attribute_hash') unless Hash === attrs - sanitize_for_mass_assignment(attrs).each do |k,v| + (guard_protected_attrs ? sanitize_for_mass_assignment(attrs) : attrs).each do |k,v| next if k.to_sym == :key if respond_to?("#{k}=") __send__("#{k}=",v) else __send__(:attribute=,k,v)