Class: Sequella::Service
- Inherits:
-
Object
- Object
- Sequella::Service
- Defined in:
- lib/sequella/service.rb
Class Method Summary collapse
-
.connection_string(params) ⇒ Object
Construct the database connection string for Sequel.
- .create_call_hook_for_connection_cleanup ⇒ Object
-
.establish_connection(connection_uri) ⇒ Object
Start the Sequel connection with the configured database.
- .qualify_path(path) ⇒ Object
- .require_models(*paths) ⇒ Object
-
.start(config) ⇒ Object
Start the Sequel connection with the configured database.
-
.stop ⇒ Object
Stop the database connection.
Class Method Details
.connection_string(params) ⇒ Object
Construct the database connection string for Sequel
64 65 66 67 68 69 |
# File 'lib/sequella/service.rb', line 64 def connection_string(params) return params[:uri] unless params[:uri].blank? raise "Must supply an adapter argument to the Sequel configuration" if params[:adapter].blank? "#{params[:adapter]}://#{params[:username]}:#{params[:password]}@#{params[:host]}:#{params[:port]}/#{params[:database]}" end |
.create_call_hook_for_connection_cleanup ⇒ Object
26 27 28 29 30 31 |
# File 'lib/sequella/service.rb', line 26 def create_call_hook_for_connection_cleanup # There does not seem to be an equivalent in Sequel #Adhearsion::Events.punchblock Punchblock::Event::Offer do # ::ActiveRecord::Base.verify_active_connections! #end end |
.establish_connection(connection_uri) ⇒ Object
Start the Sequel connection with the configured database
55 56 57 58 |
# File 'lib/sequella/service.rb', line 55 def establish_connection(connection_uri) logger.info "Sequella connecting: #{connection_uri}" ::Sequel.connect connection_uri end |
.qualify_path(path) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/sequella/service.rb', line 43 def qualify_path(path) if path =~ /^\// path else File.join Adhearsion.root, path end end |
.require_models(*paths) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/sequella/service.rb', line 33 def require_models(*paths) paths.each do |path| path = qualify_path path logger.debug "Loading Sequel models from #{path}" Dir.glob("#{path}/*.rb") do |model| require model end end end |
.start(config) ⇒ Object
Start the Sequel connection with the configured database
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/sequella/service.rb', line 8 def start(config) params = config.to_hash.select { |k, v| !v.nil? } @@connection = establish_connection connection_string(params) require_models(*params.delete(:model_paths)) # Provide Sequel a handle on the Adhearsion logger params[:loggers] = Array(params[:loggers]) << logger create_call_hook_for_connection_cleanup end |
.stop ⇒ Object
Stop the database connection
22 23 24 |
# File 'lib/sequella/service.rb', line 22 def stop logger.warn "Todo: Close down Sequel connections" end |