Sha256: 3bca672bd1254d54aaa0a132bbcd002c3644ad85fa6ed603787c304eb18f2dc9

Contents?: true

Size: 862 Bytes

Versions: 7

Compression:

Stored size: 862 Bytes

Contents

module MongoMapper
  module Plugins
    module Protected
      module ClassMethods
        def attr_protected( *attrs )
          self.write_inheritable_attribute( :attr_protected, Set.new(attrs) + (protected_attributes || []) )
        end
        def protected_attributes
          self.read_inheritable_attribute( :attr_protected )
        end
      end

      module InstanceMethods
        def update_attributes( attrs = {} )
          super filter_protected_attrs(attrs)
        end

        def update_attributes!( attrs = {} )
          super filter_protected_attrs(attrs)
        end

      protected
        def filter_protected_attrs( attrs )
          prot_attrs = self.class.protected_attributes
          return attrs  unless prot_attrs
          attrs.dup.delete_if { |key, val|  prot_attrs.include?(key) }
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
jmonteiro-mongo_mapper-0.1.7 lib/mongo_mapper/plugins/protected.rb
jmonteiro-mongo_mapper-0.1.6 lib/mongo_mapper/plugins/protected.rb
jmonteiro-mongo_mapper-0.1.5 lib/mongo_mapper/plugins/protected.rb
jmonteiro-mongo_mapper-0.1.4 lib/mongo_mapper/plugins/protected.rb
jmonteiro-mongo_mapper-0.1.2 lib/mongo_mapper/plugins/protected.rb
jmonteiro-mongo_mapper-0.1.1 lib/mongo_mapper/plugins/protected.rb
jmonteiro-mongo_mapper-0.1.0 lib/mongo_mapper/plugins/protected.rb