Class: Purobu::DatabaseConnection
- Inherits:
-
Object
- Object
- Purobu::DatabaseConnection
- Defined in:
- lib/purobu/database_connection.rb
Defined Under Namespace
Modules: Helper
Instance Attribute Summary collapse
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #connect ⇒ Object
-
#initialize(url) ⇒ DatabaseConnection
constructor
A new instance of DatabaseConnection.
Constructor Details
#initialize(url) ⇒ DatabaseConnection
Returns a new instance of DatabaseConnection.
8 9 10 |
# File 'lib/purobu/database_connection.rb', line 8 def initialize(url) @url = url end |
Instance Attribute Details
#url ⇒ Object (readonly)
Returns the value of attribute url.
6 7 8 |
# File 'lib/purobu/database_connection.rb', line 6 def url @url end |
Instance Method Details
#connect ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/purobu/database_connection.rb', line 12 def connect attempts = 0 begin connection = Sequel.connect(url) rescue => e Purobu.log(connection_failure: "Connection attempt to '#{@url}' failed.") end if block_given? begin yield connection ensure connection.disconnect end else return connection end end |