Class: Sqldump::Connector
- Inherits:
-
Object
- Object
- Sqldump::Connector
- Defined in:
- lib/sqldump/connector.rb
Instance Method Summary collapse
- #connect ⇒ Object
- #get_driver ⇒ Object
- #get_password ⇒ Object
- #get_url ⇒ Object
- #get_user ⇒ Object
-
#initialize(options) ⇒ Connector
constructor
A new instance of Connector.
- #use_host ⇒ Object
Constructor Details
#initialize(options) ⇒ Connector
Returns a new instance of Connector.
7 8 9 |
# File 'lib/sqldump/connector.rb', line 7 def initialize() @options = end |
Instance Method Details
#connect ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/sqldump/connector.rb', line 11 def connect begin dbh = DBI.connect(get_url, get_user, get_password) yield dbh ensure dbh.disconnect if dbh end end |
#get_driver ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/sqldump/connector.rb', line 31 def get_driver case @options.database_type when :sqlite3 "SQLite3" when :postgresql "Pg" when :mysql "Mysql" else raise "Unknown database type " + @options.database_type end end |
#get_password ⇒ Object
52 53 54 |
# File 'lib/sqldump/connector.rb', line 52 def get_password @options.password end |
#get_url ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/sqldump/connector.rb', line 22 def get_url driver = get_driver url = "DBI:#{driver}:#{@options.database}" if use_host url += ":#{@options.host}" end url end |
#get_user ⇒ Object
48 49 50 |
# File 'lib/sqldump/connector.rb', line 48 def get_user @options.username end |
#use_host ⇒ Object
44 45 46 |
# File 'lib/sqldump/connector.rb', line 44 def use_host @options.database_type != :sqlite3 end |