Module: PeaceLove

Defined in:
lib/peace_love.rb,
lib/peace_love/db.rb,
lib/peace_love/cursor.rb,
lib/peace_love/document.rb,
lib/peace_love/collection.rb,
lib/peace_love/oid_helper.rb

Defined Under Namespace

Modules: Doc, OidHelper Classes: Collection, Cursor, Db

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.connectionObject

Returns the value of attribute connection.



12
13
14
# File 'lib/peace_love.rb', line 12

def connection
  @connection
end

.default_dbObject

Returns the value of attribute default_db.



12
13
14
# File 'lib/peace_love.rb', line 12

def default_db
  @default_db
end

.mongoObject

Returns the value of attribute mongo.



12
13
14
# File 'lib/peace_love.rb', line 12

def mongo
  @mongo
end

Class Method Details

.[](*db_name) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/peace_love.rb', line 18

def [](*db_name)
  if db_name = db_name.flatten.compact.pop
    dbs[db_name.to_s] ||= PeaceLove::Db.new( mongo[db_name], mixin_config[db_name] )
  else
    @wrapped_default_db ||= PeaceLove::Db.new( default_db, mixin_config[nil] )
  end
end

.collection_for_mixin(mixin) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/peace_love.rb', line 30

def collection_for_mixin(mixin)
  mixin_config.each do |db,db_mixins|
    db_mixins.each do |col,col_mixin|
      if col_mixin == mixin
        return self[db][col]
      end
    end
  end
end

.connect(options) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/peace_love.rb', line 40

def connect(options)
  options = AngryHash[options]

  if options.port?
    options.port = options.port.to_i
  end

  options.delete('adapter') # XXX check?

  self.connection = Mongo::Connection.new(options.delete('host'), options.delete('port'), options)
  self.default_db = connection.db(options.database)
end

.dbsObject



14
15
16
# File 'lib/peace_love.rb', line 14

def dbs
  @dbs ||= {}
end

.mixin_configObject



26
27
28
# File 'lib/peace_love.rb', line 26

def mixin_config
  @mixin_config ||= Hash.new {|h,k| h[k] = {}}
end