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
mongo_mapper-unstable-2010.07.15 lib/mongo_mapper/plugins/accessible.rb
mongo_mapper-unstable-2010.07.14 lib/mongo_mapper/plugins/accessible.rb
mongo_mapper-unstable-2010.07.13 lib/mongo_mapper/plugins/accessible.rb
mongo_mapper-unstable-2010.07.12 lib/mongo_mapper/plugins/accessible.rb
mongo_mapper-unstable-2010.07.09 lib/mongo_mapper/plugins/accessible.rb
mongo_mapper-unstable-2010.07.08 lib/mongo_mapper/plugins/accessible.rb
mongo_mapper-unstable-2010.07.07 lib/mongo_mapper/plugins/accessible.rb
mongo_mapper-unstable-2010.07.06 lib/mongo_mapper/plugins/accessible.rb
mongo_mapper-unstable-2010.07.05 lib/mongo_mapper/plugins/accessible.rb
mongo_mapper-unstable-2010.07.02 lib/mongo_mapper/plugins/accessible.rb
mongo_mapper-unstable-2010.07.01 lib/mongo_mapper/plugins/accessible.rb
mongo_mapper-unstable-2010.06.30 lib/mongo_mapper/plugins/accessible.rb
mongo_mapper-unstable-2010.06.29 lib/mongo_mapper/plugins/accessible.rb
mongo_mapper-unstable-2010.06.28 lib/mongo_mapper/plugins/accessible.rb
mongo_mapper-unstable-2010.06.25 lib/mongo_mapper/plugins/accessible.rb
mongo_mapper-unstable-2010.06.24 lib/mongo_mapper/plugins/accessible.rb
mongo_mapper-unstable-2010.06.23 lib/mongo_mapper/plugins/accessible.rb
mongo_mapper-0.8.2 lib/mongo_mapper/plugins/accessible.rb
mongo_mapper-0.8.1 lib/mongo_mapper/plugins/accessible.rb
mongo_mapper-0.8.0 lib/mongo_mapper/plugins/accessible.rb