Sha256: ce572d6e1f03337a5fd6eb0b9bc890234ae75e3a4b11f532648df029d104a2e6
Contents?: true
Size: 1.18 KB
Versions: 60
Compression:
Stored size: 1.18 KB
Contents
module MongoMapper module Plugins module Accessible module ClassMethods def attr_accessible(*attrs) raise AccessibleOrProtected.new(name) if try(:protected_attributes?) self.write_inheritable_attribute(:attr_accessible, Set.new(attrs) + (accessible_attributes || [])) end def accessible_attributes? !accessible_attributes.nil? end def accessible_attributes self.read_inheritable_attribute(:attr_accessible) end end module InstanceMethods def assign(attrs={}) super(filter_inaccessible_attrs(attrs)) end def update_attributes(attrs={}) super(filter_inaccessible_attrs(attrs)) end def update_attributes!(attrs={}) super(filter_inaccessible_attrs(attrs)) end def accessible_attributes self.class.accessible_attributes end protected def filter_inaccessible_attrs(attrs) return attrs if accessible_attributes.blank? || attrs.blank? attrs.dup.delete_if { |key, val| !accessible_attributes.include?(key.to_sym) } end end end end end
Version data entries
60 entries across 60 versions & 7 rubygems