module MongoModel::DocumentExtensions::Persistence::ClassMethods
Public Instance Methods
collection()
click to toggle source
# File lib/mongomodel/document/persistence.rb, line 121 def collection @_collection ||= InstrumentedCollection.new(database.collection(collection_name)) end
collection_name()
click to toggle source
# File lib/mongomodel/document/persistence.rb, line 104 def collection_name @_collection_name || inferred_collection_name end
collection_name=(name)
click to toggle source
# File lib/mongomodel/document/persistence.rb, line 108 def collection_name=(name) @_collection = nil @_collection_name = name end
create(attributes={}, &block)
click to toggle source
# 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()
click to toggle source
# File lib/mongomodel/document/persistence.rb, line 125 def database MongoModel.database end
from_mongo(hash)
click to toggle source
Calls superclass method
# File lib/mongomodel/document/persistence.rb, line 98 def from_mongo(hash) instance = super instance.send(:instantiate) if instance instance end
save_safely=(val)
click to toggle source
# File lib/mongomodel/document/persistence.rb, line 133 def save_safely=(val) @_save_safely = val end
save_safely?()
click to toggle source
# File lib/mongomodel/document/persistence.rb, line 129 def save_safely? defined?(@_save_safely) ? @_save_safely : true end
type_selector()
click to toggle source
# File lib/mongomodel/document/persistence.rb, line 117 def type_selector [self.to_s] + descendants.map { |m| m.to_s } end
use_type_selector?()
click to toggle source
# File lib/mongomodel/document/persistence.rb, line 113 def use_type_selector? !superclass.abstract_class? end
Protected Instance Methods
inferred_collection_name()
click to toggle source
# File lib/mongomodel/document/persistence.rb, line 138 def inferred_collection_name if superclass.abstract_class? name.tableize.gsub(/\//, '.') else superclass.collection_name end end