Sha256: f0530c8d5630fb7b6367b9b95261a0da9aafa9fe5f954b52a019f8ab926bc5ec

Contents?: true

Size: 1.03 KB

Versions: 10

Compression:

Stored size: 1.03 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 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

10 entries across 10 versions & 2 rubygems

Version Path
novelys_mongo_mapper-0.6.12 lib/novelys_mongo_mapper/plugins/protected.rb
novelys_mongo_mapper-0.6.11 lib/novelys_mongo_mapper/plugins/protected.rb
mongo_mapper-unstable-2010.2.3 lib/mongo_mapper/plugins/protected.rb
novelys_mongo_mapper-0.6.10 lib/mongo_mapper/plugins/protected.rb
mongo_mapper-unstable-2010.2.2 lib/mongo_mapper/plugins/protected.rb
mongo_mapper-unstable-2010.2.1 lib/mongo_mapper/plugins/protected.rb
mongo_mapper-unstable-2010.1.31 lib/mongo_mapper/plugins/protected.rb
mongo_mapper-unstable-2010.1.30 lib/mongo_mapper/plugins/protected.rb
mongo_mapper-unstable-2010.1.29 lib/mongo_mapper/plugins/protected.rb
mongo_mapper-unstable-2010.1.28 lib/mongo_mapper/plugins/protected.rb