Sha256: 330192beaaeb4bc568c073fce214beae8dcf6a3afaf457223b3afbcdfabc0e04

Contents?: true

Size: 925 Bytes

Versions: 5

Compression:

Stored size: 925 Bytes

Contents

# encoding: UTF-8
module MongoMapper
  module Plugins
    module Sci
      extend ActiveSupport::Concern

      included do
        extend ActiveSupport::DescendantsTracker
      end

      module ClassMethods
        def inherited(subclass)
          key :_type, String unless key?(:_type)
          subclass.instance_variable_set("@single_collection_inherited", true)
          subclass.set_collection_name(collection_name) unless subclass.embeddable?
          super
        end

        def single_collection_inherited?
          @single_collection_inherited == true
        end

        def query(options={})
          super.tap do |query|
            query[:_type] = {'$in' => [name] + descendants.map(&:name)} if single_collection_inherited?
          end
        end
      end

      def initialize(*args)
        super
        write_key :_type, self.class.name if self.class.key?(:_type)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 3 rubygems

Version Path
lookout-mongo_mapper-0.11.3 lib/mongo_mapper/plugins/sci.rb
mongo_mapper-0.11.2 lib/mongo_mapper/plugins/sci.rb
jamieorc-mongo_mapper-0.11.1.1 lib/mongo_mapper/plugins/sci.rb
mongo_mapper-0.11.1 lib/mongo_mapper/plugins/sci.rb
mongo_mapper-0.11.0 lib/mongo_mapper/plugins/sci.rb