Class: Purview::Connections::Base
- Defined in:
- lib/purview/connections/base.rb
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
- #disconnect ⇒ Object
- #execute(sql) ⇒ Object
-
#initialize(opts) ⇒ Base
constructor
A new instance of Base.
- #with_transaction ⇒ Object
Constructor Details
#initialize(opts) ⇒ Base
Returns a new instance of Base.
14 15 16 |
# File 'lib/purview/connections/base.rb', line 14 def initialize(opts) @raw_connection = raw_connection_type.connect(opts) end |
Class Method Details
.connect(opts) ⇒ Object
4 5 6 |
# File 'lib/purview/connections/base.rb', line 4 def self.connect(opts) new(opts) end |
.with_new_connection(opts) ⇒ Object
8 9 10 11 12 |
# File 'lib/purview/connections/base.rb', line 8 def self.with_new_connection(opts) yield connection = connect(opts) ensure connection.disconnect if connection end |
Instance Method Details
#disconnect ⇒ Object
18 19 20 21 22 |
# File 'lib/purview/connections/base.rb', line 18 def disconnect raw_connection.disconnect @raw_connection = nil self end |
#execute(sql) ⇒ Object
24 25 26 |
# File 'lib/purview/connections/base.rb', line 24 def execute(sql) raw_connection.execute(sql) end |
#with_transaction ⇒ Object
28 29 30 |
# File 'lib/purview/connections/base.rb', line 28 def with_transaction raw_connection.with_transaction { yield } end |