Class: RStore::BaseDB
Class Attribute Summary collapse
-
.db_classes ⇒ Hash{Symbol=>BaseDB}
readonly
A Hash holding subclasses of BaseDB.
Class Method Summary collapse
-
.connect {|db| ... } ⇒ void
Uses the connection info from BaseDB.info to connect to the database.
-
.info(options) ⇒ void
Define the database connection.
- .inherited(subclass) ⇒ Object
-
.name ⇒ Symbol
The lower-case class name without the DB postfix.
Class Attribute Details
.db_classes ⇒ Hash{Symbol=>BaseDB} (readonly)
A Hash holding subclasses of RStore::BaseDB
23 24 25 |
# File 'lib/rstore/base_db.rb', line 23 def db_classes @db_classes end |
Class Method Details
.connect {|db| ... } ⇒ void
Note:
To be called when defining a subclass of RStore::BaseDB
This method returns an undefined value.
Uses the connection info from info to connect to the database.
103 104 105 |
# File 'lib/rstore/base_db.rb', line 103 def self.connect &block Sequel.connect(@connection_info, &block) end |
.info(options) ⇒ void
Note:
To be called when defining a subclass of RStore::BaseDB
Define the database connection. Accepts the same one arity parameters as [Sequel.connect](sequel.rubyforge.org/rdoc/files/doc/opening_databases_rdoc.html)
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/rstore/base_db.rb', line 58 def self.info hash_or_string # self = CompanyDB class << self # self = #<Class:CompanyDB> attr_reader :connection_info end # Instance variables always belong to self. @connection_info = hash_or_string.is_a?(Hash) ? hash_or_string.merge(:database => self.name.to_s): hash_or_string end |
.inherited(subclass) ⇒ Object
29 30 31 |
# File 'lib/rstore/base_db.rb', line 29 def self.inherited subclass BaseDB.db_classes[subclass.name] = subclass end |
.name ⇒ Symbol
Returns The lower-case class name without the DB postfix.
117 118 119 |
# File 'lib/rstore/base_db.rb', line 117 def self.name super.gsub!(/DB/,'').downcase.to_sym end |