Sha256: eeabe2617e2fd8fce76f0a0631a22ce1b3ee3ee2e54a6780360753c80c044f65

Contents?: true

Size: 1.12 KB

Versions: 14

Compression:

Stored size: 1.12 KB

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

        def key(*args)
          key = super
          attr_protected key.name.to_sym if key.options[:protected]
          key
        end
      end

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

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

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

        def protected_attributes
          self.class.protected_attributes
        end

        protected
          def filter_protected_attrs(attrs)
            return attrs if protected_attributes.blank?
            attrs.dup.delete_if { |key, val| protected_attributes.include?(key) }
          end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 3 rubygems

Version Path
drogus-mongo_mapper-0.6.10 lib/mongo_mapper/plugins/protected.rb
mongo_mapper-unstable-2010.2.19 lib/mongo_mapper/plugins/protected.rb
mongo_mapper-unstable-2010.2.18 lib/mongo_mapper/plugins/protected.rb
mongo_mapper-unstable-2010.2.17 lib/mongo_mapper/plugins/protected.rb
mongo_mapper-unstable-2010.2.16 lib/mongo_mapper/plugins/protected.rb
mongo_mapper-unstable-2010.2.15 lib/mongo_mapper/plugins/protected.rb
mongo_mapper-unstable-2010.2.12 lib/mongo_mapper/plugins/protected.rb
mongo_mapper-unstable-2010.2.11 lib/mongo_mapper/plugins/protected.rb
mongo_mapper-unstable-2010.2.10 lib/mongo_mapper/plugins/protected.rb
mongo_mapper-0.7.0 lib/mongo_mapper/plugins/protected.rb
mongo_mapper-unstable-2010.2.9 lib/mongo_mapper/plugins/protected.rb
mongo_mapper-unstable-2010.2.8 lib/mongo_mapper/plugins/protected.rb
mongo_mapper-unstable-2010.2.5 lib/mongo_mapper/plugins/protected.rb
mongo_mapper-unstable-2010.2.4 lib/mongo_mapper/plugins/protected.rb