Class: RDBI::Driver
- Inherits:
-
Object
- Object
- RDBI::Driver
- Defined in:
- lib/rdbi/driver.rb
Overview
RDBI::Driver is the bootstrap handle to yield database connection (RDBI::Database) handles. It preserves the connection parameters and the desired database, and outside of yielding handles, does little else.
As such, it is normally intended to be used by RDBI internally and (rarely by) Database drivers.
Instance Attribute Summary collapse
-
#connect_args ⇒ Object
readonly
connection arguments requested during initialization.
-
#dbh_class ⇒ Object
readonly
Database driver class requested for initialization.
Instance Method Summary collapse
-
#initialize(dbh_class, *args) ⇒ Driver
constructor
Initialize a new driver object.
-
#new_handle ⇒ Object
This is a proxy method to construct RDBI::Database handles.
Constructor Details
#initialize(dbh_class, *args) ⇒ Driver
Initialize a new driver object. This accepts an RDBI::Database subclass as a class name (shorthand does not work here) and the arguments to pass into the constructor.
18 19 20 21 22 23 24 |
# File 'lib/rdbi/driver.rb', line 18 def initialize(dbh_class, *args) @dbh_class = dbh_class if args.empty? raise ArgumentError, "unable to connect without arguments" end @connect_args = [RDBI::Util.key_hash_as_symbols(args[0])] end |
Instance Attribute Details
#connect_args ⇒ Object (readonly)
connection arguments requested during initialization
11 12 13 |
# File 'lib/rdbi/driver.rb', line 11 def connect_args @connect_args end |
#dbh_class ⇒ Object (readonly)
Database driver class requested for initialization
13 14 15 |
# File 'lib/rdbi/driver.rb', line 13 def dbh_class @dbh_class end |
Instance Method Details
#new_handle ⇒ Object
This is a proxy method to construct RDBI::Database handles. It constructs the RDBI::Database object, and sets the driver on the object to this current object for duplication / multiple creation.
31 32 33 34 35 |
# File 'lib/rdbi/driver.rb', line 31 def new_handle dbh = @dbh_class.new(*@connect_args) dbh.driver = self return dbh end |