Module: MongoMapper::Plugins::Sci::ClassMethods
- Defined in:
- lib/mongo_mapper/plugins/sci.rb
Instance Method Summary collapse
- #criteria_hash(criteria = {}) ⇒ Object
- #explicit_collection_defined? ⇒ Boolean
- #inherited(subclass) ⇒ Object
- #query(options = {}) ⇒ Object
- #set_collection_name(name) ⇒ Object
- #single_collection_inherited? ⇒ Boolean
- #single_collection_parent ⇒ Object
- #single_collection_parent=(parent) ⇒ Object
- #single_collection_root ⇒ Object
Instance Method Details
#criteria_hash(criteria = {}) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/mongo_mapper/plugins/sci.rb', line 35 def criteria_hash(criteria={}) if single_collection_inherited? super criteria.merge(:_type => name) else super end end |
#explicit_collection_defined? ⇒ Boolean
53 54 55 |
# File 'lib/mongo_mapper/plugins/sci.rb', line 53 def explicit_collection_defined? @collection_defined == true end |
#inherited(subclass) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/mongo_mapper/plugins/sci.rb', line 12 def inherited(subclass) super if @collection_name == subclass.instance_variable_get("@collection_name") key :_type, String unless key?(:_type) subclass.single_collection_parent = self subclass.instance_variable_set("@single_collection_inherited", true) else remove_key :_type end end |
#query(options = {}) ⇒ Object
69 70 71 72 73 |
# File 'lib/mongo_mapper/plugins/sci.rb', line 69 def query(={}) super.tap do |query| query[:_type] = {'$in' => [name] + descendants.map(&:name)} if single_collection_inherited? end end |
#set_collection_name(name) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/mongo_mapper/plugins/sci.rb', line 43 def set_collection_name(name) if single_collection_inherited? single_collection_parent.remove_key :_type single_collection_parent = nil @single_collection_inherited = false end @collection_defined = true super end |
#single_collection_inherited? ⇒ Boolean
65 66 67 |
# File 'lib/mongo_mapper/plugins/sci.rb', line 65 def single_collection_inherited? !!(@single_collection_inherited ||= false) end |
#single_collection_parent ⇒ Object
57 58 59 |
# File 'lib/mongo_mapper/plugins/sci.rb', line 57 def single_collection_parent @single_collection_parent end |
#single_collection_parent=(parent) ⇒ Object
61 62 63 |
# File 'lib/mongo_mapper/plugins/sci.rb', line 61 def single_collection_parent=(parent) @single_collection_parent = parent end |