Module: ActivePStore::ConnectionHandling
- Included in:
- Base
- Defined in:
- lib/active_pstore/connection_handling.rb
Instance Method Summary collapse
Instance Method Details
#establish_connection(options) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/active_pstore/connection_handling.rb', line 5 def establish_connection() unless .is_a? Hash raise ArgumentError, "You must specify at database configuration. Example: ActivePStore::Base.establish_connection(database: '/path/to/file')" end @@db = PStore.new(([:database] || ['database']).to_s) end |
#use_connection ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/active_pstore/connection_handling.rb', line 13 def use_connection @@db.transaction do |pstore| yield pstore end rescue # uninitialized class variable @@db in ActivePStore::Base raise ActivePStore::ConnectionNotEstablished, "Raised when connection to the pstore file path could not been established (for example when ActivePStore.establish_connection(database: '/path/to/file') is given a nil object)." end |