Class: Toaster::DB

Inherits:
Object
  • Object
show all
Defined in:
lib/toaster/db/db.rb

Direct Known Subclasses

MysqlDB

Constant Summary collapse

@@instance =
nil

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.DEFAULT_COLLObject

Returns the value of attribute DEFAULT_COLL.



15
16
17
# File 'lib/toaster/db/db.rb', line 15

def DEFAULT_COLL
  @DEFAULT_COLL
end

.DEFAULT_DBObject

Returns the value of attribute DEFAULT_DB.



15
16
17
# File 'lib/toaster/db/db.rb', line 15

def DEFAULT_DB
  @DEFAULT_DB
end

.DEFAULT_HOSTObject

Returns the value of attribute DEFAULT_HOST.



15
16
17
# File 'lib/toaster/db/db.rb', line 15

def DEFAULT_HOST
  @DEFAULT_HOST
end

.DEFAULT_PORTObject

Returns the value of attribute DEFAULT_PORT.



15
16
17
# File 'lib/toaster/db/db.rb', line 15

def DEFAULT_PORT
  @DEFAULT_PORT
end

.DEFAULT_REQUIREObject

Returns the value of attribute DEFAULT_REQUIRE.



15
16
17
# File 'lib/toaster/db/db.rb', line 15

def DEFAULT_REQUIRE
  @DEFAULT_REQUIRE
end

.DEFAULT_TYPEObject

Returns the value of attribute DEFAULT_TYPE.



15
16
17
# File 'lib/toaster/db/db.rb', line 15

def DEFAULT_TYPE
  @DEFAULT_TYPE
end

.IMPL_CLASSESObject

Returns the value of attribute IMPL_CLASSES.



15
16
17
# File 'lib/toaster/db/db.rb', line 15

def IMPL_CLASSES
  @IMPL_CLASSES
end

.REQUIRE_PATHObject

Returns the value of attribute REQUIRE_PATH.



15
16
17
# File 'lib/toaster/db/db.rb', line 15

def REQUIRE_PATH
  @REQUIRE_PATH
end

.USE_CACHEObject

Returns the value of attribute USE_CACHE.



15
16
17
# File 'lib/toaster/db/db.rb', line 15

def USE_CACHE
  @USE_CACHE
end

Instance Attribute Details

#db_collectionObject

Returns the value of attribute db_collection.



61
62
63
# File 'lib/toaster/db/db.rb', line 61

def db_collection
  @db_collection
end

#db_hostObject

Returns the value of attribute db_host.



61
62
63
# File 'lib/toaster/db/db.rb', line 61

def db_host
  @db_host
end

#db_nameObject

Returns the value of attribute db_name.



61
62
63
# File 'lib/toaster/db/db.rb', line 61

def db_name
  @db_name
end

#db_portObject

Returns the value of attribute db_port.



61
62
63
# File 'lib/toaster/db/db.rb', line 61

def db_port
  @db_port
end

Class Method Details

.find_activerecord(clazz, criteria) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/toaster/db/db.rb', line 48

def self.find_activerecord(clazz, criteria)
  if criteria.kind_of?(String)
    criteria = criteria.to_i
  end
  if numeric?(criteria)
    return clazz.find_by(:id => criteria)
  elsif !criteria || criteria.empty?
    return clazz.all
  else
    return clazz.where(criteria)
  end
end

.instance(host = nil, port = nil, db = nil, collection = nil, type = nil) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/toaster/db/db.rb', line 32

def self.instance(host = nil, port = nil, db = nil, collection = nil, type = nil)
  host = self.DEFAULT_HOST if Util.empty?(host)
  port = self.DEFAULT_PORT if Util.empty?(port)
  db = self.DEFAULT_DB if Util.empty?(db)
  collection = self.DEFAULT_COLL if Util.empty?(collection)
  type = self.DEFAULT_TYPE if Util.empty?(type)

  @@instances ||= {}
  key = get_key(type, host, port, db, collection)
  return @@instances[key] if @@instances[key]

  #puts "Using DB connection #{host}:#{port}, db '#{db}', collection '#{collection}'"

  init_instance(type, host, port, db, collection)
end