Module: ActivePStore::ConnectionHandling
- Included in:
- Base
- Defined in:
- lib/active_pstore/connection_handling.rb
Instance Method Summary collapse
Instance Method Details
#connection_config ⇒ Object
5 6 7 |
# File 'lib/active_pstore/connection_handling.rb', line 5 def connection_config @@config.dup.freeze end |
#establish_connection(options) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/active_pstore/connection_handling.rb', line 9 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 @@config = {database: ([:database] || ['database']).to_s} @@db = PStore.new(@@config[:database]) end |
#use_connection ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/active_pstore/connection_handling.rb', line 19 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 |