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

Version Path
jonbell-mongo_mapper-0.8.6 lib/mongo_mapper/plugins/accessible.rb
ign-mongo_mapper-0.8.6.2 lib/mongo_mapper/plugins/accessible.rb
ign-mongo_mapper-0.8.6.1 lib/mongo_mapper/plugins/accessible.rb
ssherman-mongo_mapper-0.8.6 lib/mongo_mapper/plugins/accessible.rb
mongo_mapper-0.8.6 lib/mongo_mapper/plugins/accessible.rb
mongo_mapper-0.8.5 lib/mongo_mapper/plugins/accessible.rb
honkster-mongo_mapper-0.8.4 lib/mongo_mapper/plugins/accessible.rb
mongo_mapper-0.8.4 lib/mongo_mapper/plugins/accessible.rb
mongo_mapper-unstable-2010.08.19 lib/mongo_mapper/plugins/accessible.rb
mongo_mapper-unstable-2010.08.18 lib/mongo_mapper/plugins/accessible.rb
mongo_mapper-unstable-2010.08.17 lib/mongo_mapper/plugins/accessible.rb
mongo_mapper-unstable-2010.08.16 lib/mongo_mapper/plugins/accessible.rb
mongo_mapper-unstable-2010.08.15 lib/mongo_mapper/plugins/accessible.rb
mongo_mapper-unstable-2010.08.14 lib/mongo_mapper/plugins/accessible.rb
mongo_mapper-unstable-2010.08.13 lib/mongo_mapper/plugins/accessible.rb
mongo_mapper-unstable-2010.08.12 lib/mongo_mapper/plugins/accessible.rb
mongo_mapper-unstable-2010.08.11 lib/mongo_mapper/plugins/accessible.rb
mongo_mapper-unstable-2010.08.10 lib/mongo_mapper/plugins/accessible.rb
mongo_mapper-unstable-2010.08.09 lib/mongo_mapper/plugins/accessible.rb
mongo_mapper-0.8.3 lib/mongo_mapper/plugins/accessible.rb