Module: MongoODM

Extended by:
ActiveSupport::Autoload
Defined in:
lib/mongo_odm.rb,
lib/mongo_odm/errors.rb,
lib/mongo_odm/cursor.rb,
lib/mongo_odm/config.rb,
lib/mongo_odm/version.rb,
lib/mongo_odm/document.rb,
lib/mongo_odm/criteria.rb,
lib/mongo_odm/collection.rb,
lib/mongo_odm/document/fields.rb,
lib/mongo_odm/document/indexes.rb,
lib/mongo_odm/document/inspect.rb,
lib/mongo_odm/document/equality.rb,
lib/mongo_odm/document/callbacks.rb,
lib/mongo_odm/document/timestamps.rb,
lib/mongo_odm/document/persistence.rb,
lib/mongo_odm/document/validations.rb,
lib/mongo_odm/document/attribute_methods.rb,
lib/mongo_odm/document/attribute_methods/read.rb,
lib/mongo_odm/document/attribute_methods/query.rb,
lib/mongo_odm/document/attribute_methods/write.rb,
lib/mongo_odm/document/attribute_methods/dirty.rb,
lib/mongo_odm/document/attribute_methods/inspect.rb,
lib/mongo_odm/document/attribute_methods/localization.rb,
lib/mongo_odm/document/validations/uniqueness_validator.rb

Overview

Contains the classes and modules related to the ODM built on top of the basic Mongo client.

Defined Under Namespace

Modules: Document, Errors Classes: Collection, Config, Criteria, Cursor

Constant Summary

VERSION_MAJOR =
"0"
VERSION_MINOR =
"2"
VERSION_BUILD =
"20"
VERSION =
"#{VERSION_MAJOR}.#{VERSION_MINOR}.#{VERSION_BUILD}"

Class Method Summary (collapse)

Class Method Details

+ (Object) add_index_class(klass)



63
64
65
# File 'lib/mongo_odm.rb', line 63

def self.add_index_class(klass)
  indexed_classes << klass
end

+ (Object) config



33
34
35
# File 'lib/mongo_odm.rb', line 33

def self.config
  @_config ||= Config.new
end

+ (Object) config=(value)



37
38
39
40
# File 'lib/mongo_odm.rb', line 37

def self.config=(value)
  self.connection = nil
  @_config = value.is_a?(Config) ? value : Config.new(value)
end

+ (Object) connection



21
22
23
# File 'lib/mongo_odm.rb', line 21

def self.connection
  Thread.current[:mongo_odm_connection] ||= config.connection
end

+ (Object) connection=(value)



25
26
27
# File 'lib/mongo_odm.rb', line 25

def self.connection=(value)
  Thread.current[:mongo_odm_connection] = value
end

+ (Object) create_indexes



59
60
61
# File 'lib/mongo_odm.rb', line 59

def self.create_indexes
  indexed_classes.each {|klass| klass.create_indexes}
end

+ (Object) database



29
30
31
# File 'lib/mongo_odm.rb', line 29

def self.database
  Thread.current[:mongo_odm_database] ||= self.connection.db( config.database )
end

+ (Object) dereference(value)



51
52
53
# File 'lib/mongo_odm.rb', line 51

def self.dereference(value)
  value.respond_to?(:dereference) ? value.dereference : value
end

+ (Object) indexed_classes



55
56
57
# File 'lib/mongo_odm.rb', line 55

def self.indexed_classes
  @_indexes ||= Set.new
end

+ (Object) instanciate(value)



42
43
44
45
46
47
48
49
# File 'lib/mongo_odm.rb', line 42

def self.instanciate(value)
  return value if value.is_a?(MongoODM::Document)
  if value.is_a?(Hash)
    klass = value["_class"] || value[:_class]
    return klass.constantize.new(value) if klass
  end
  value.class.type_cast(value.to_mongo)
end