Module: MongoModel::DocumentExtensions::Persistence::ClassMethods
- Defined in:
- lib/mongomodel/document/persistence.rb
Instance Method Summary collapse
- #collection ⇒ Object
- #collection_name ⇒ Object
- #collection_name=(name) ⇒ Object
- #create(attributes = {}, &block) ⇒ Object
- #database ⇒ Object
- #from_mongo(hash) ⇒ Object
- #save_safely=(val) ⇒ Object
- #save_safely? ⇒ Boolean
- #type_selector ⇒ Object
- #use_type_selector? ⇒ Boolean
Instance Method Details
#collection ⇒ Object
121 122 123 |
# File 'lib/mongomodel/document/persistence.rb', line 121 def collection @_collection ||= InstrumentedCollection.new(database.collection(collection_name)) end |
#collection_name ⇒ Object
104 105 106 |
# File 'lib/mongomodel/document/persistence.rb', line 104 def collection_name @_collection_name || inferred_collection_name end |
#collection_name=(name) ⇒ Object
108 109 110 111 |
# File 'lib/mongomodel/document/persistence.rb', line 108 def collection_name=(name) @_collection = nil @_collection_name = name end |
#create(attributes = {}, &block) ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'lib/mongomodel/document/persistence.rb', line 88 def create(attributes={}, &block) if attributes.is_a?(Array) attributes.map { |attrs| create(attrs, &block) } else instance = new(attributes, &block) instance.save instance end end |
#database ⇒ Object
125 126 127 |
# File 'lib/mongomodel/document/persistence.rb', line 125 def database MongoModel.database end |
#from_mongo(hash) ⇒ Object
98 99 100 101 102 |
# File 'lib/mongomodel/document/persistence.rb', line 98 def from_mongo(hash) instance = super instance.send(:instantiate) if instance instance end |
#save_safely=(val) ⇒ Object
133 134 135 |
# File 'lib/mongomodel/document/persistence.rb', line 133 def save_safely=(val) @_save_safely = val end |
#save_safely? ⇒ Boolean
129 130 131 |
# File 'lib/mongomodel/document/persistence.rb', line 129 def save_safely? defined?(@_save_safely) ? @_save_safely : true end |
#type_selector ⇒ Object
117 118 119 |
# File 'lib/mongomodel/document/persistence.rb', line 117 def type_selector [self.to_s] + descendants.map { |m| m.to_s } end |
#use_type_selector? ⇒ Boolean
113 114 115 |
# File 'lib/mongomodel/document/persistence.rb', line 113 def use_type_selector? !superclass.abstract_class? end |