-
Notifications
You must be signed in to change notification settings - Fork 382
/
sci.rb
36 lines (31 loc) · 925 Bytes
/
sci.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 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