Class: Sequella::Plugin::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/sequella/plugin/service.rb

Class Method Summary collapse

Class Method Details

.create_call_hook_for_connection_cleanupObject



28
29
30
31
32
33
# File 'lib/sequella/plugin/service.rb', line 28

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(params) ⇒ Object

Start the Sequel connection with the configured database

Parameters:

  • params (Hash)

    Options to establish the database connection



57
58
59
# File 'lib/sequella/plugin/service.rb', line 57

def establish_connection(params)
  ::Sequel.connect params
end

.qualify_path(path) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/sequella/plugin/service.rb', line 45

def qualify_path(path)
  if path =~ /^\//
    path
  else
    File.join Adhearsion.root, path
  end
end

.require_models(*paths) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/sequella/plugin/service.rb', line 35

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
19
20
# File 'lib/sequella/plugin/service.rb', line 8

def start(config)
  raise "Must supply an adapter argument to the Sequel configuration" if (config.adapter.nil? || config.adapter.empty?)

  params = config.to_hash.select { |k,v| !v.nil? }

  @@connection = establish_connection 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

.stopObject

Stop the database connection



24
25
26
# File 'lib/sequella/plugin/service.rb', line 24

def stop
  logger.warn "Todo: Close down Sequel connections"
end