Class: Toaster::DB
- Inherits:
-
Object
- Object
- Toaster::DB
- Defined in:
- lib/toaster/db/db.rb
Direct Known Subclasses
Constant Summary collapse
- @@instance =
nil
Class Attribute Summary collapse
-
.DEFAULT_COLL ⇒ Object
Returns the value of attribute DEFAULT_COLL.
-
.DEFAULT_DB ⇒ Object
Returns the value of attribute DEFAULT_DB.
-
.DEFAULT_HOST ⇒ Object
Returns the value of attribute DEFAULT_HOST.
-
.DEFAULT_PORT ⇒ Object
Returns the value of attribute DEFAULT_PORT.
-
.DEFAULT_REQUIRE ⇒ Object
Returns the value of attribute DEFAULT_REQUIRE.
-
.DEFAULT_TYPE ⇒ Object
Returns the value of attribute DEFAULT_TYPE.
-
.IMPL_CLASSES ⇒ Object
Returns the value of attribute IMPL_CLASSES.
-
.REQUIRE_PATH ⇒ Object
Returns the value of attribute REQUIRE_PATH.
-
.USE_CACHE ⇒ Object
Returns the value of attribute USE_CACHE.
Instance Attribute Summary collapse
-
#db_collection ⇒ Object
Returns the value of attribute db_collection.
-
#db_host ⇒ Object
Returns the value of attribute db_host.
-
#db_name ⇒ Object
Returns the value of attribute db_name.
-
#db_port ⇒ Object
Returns the value of attribute db_port.
Class Method Summary collapse
- .find_activerecord(clazz, criteria) ⇒ Object
- .instance(host = nil, port = nil, db = nil, collection = nil, type = nil) ⇒ Object
Class Attribute Details
.DEFAULT_COLL ⇒ Object
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_DB ⇒ Object
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_HOST ⇒ Object
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_PORT ⇒ Object
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_REQUIRE ⇒ Object
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_TYPE ⇒ Object
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_CLASSES ⇒ Object
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_PATH ⇒ Object
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_CACHE ⇒ Object
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_collection ⇒ Object
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_host ⇒ Object
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_name ⇒ Object
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_port ⇒ Object
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 |