Class: Elastix::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/elastix/base.rb

Direct Known Subclasses

Extension

Class Method Summary collapse

Class Method Details

.close_db_connectionObject



27
28
29
# File 'lib/elastix/base.rb', line 27

def self.close_db_connection
  ActiveRecord::Base.connection.close
end

.establish_connection(web_options = {}, db_options = {}) ⇒ Object



22
23
24
25
# File 'lib/elastix/base.rb', line 22

def self.establish_connection(web_options={}, db_options={})
  establish_web_connection(web_options[:host], web_options[:username], web_options[:password])
  establish_db_connection(db_options[:host], db_options[:username], db_options[:password])
end

.establish_db_connection(host, username, password) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/elastix/base.rb', line 12

def self.establish_db_connection(host, username, password)
  ActiveRecord::Base.establish_connection(
    :adapter  => "mysql2",
    :host     => host,
    :database => "asterisk",
    :username => username,
    :password => password,
  )
end

.establish_web_connection(host, username, password) ⇒ Object



4
5
6
7
8
9
# File 'lib/elastix/base.rb', line 4

def self.establish_web_connection host, username, password
  @@elastix = Mechanize.new
  @@elastix.agent.http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  @@base_address = "https://#{host}"
   username, password
end

.reloadObject



40
41
42
# File 'lib/elastix/base.rb', line 40

def self.reload
  @@elastix.get("#{@@base_address}/config.php?handler=reload")
end

.web_connected?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/elastix/base.rb', line 36

def self.web_connected?
  @@elastix.current_page.title != "Elastix - Login page"
end