Class: Connectator::Base::Connection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Connection

Returns a new instance of Connection.



6
7
8
9
10
11
12
13
14
# File 'lib/connectator/base/connection.rb', line 6

def initialize(opts = {})
  raise "Connection Options are required" if opts.empty?
  connection_params.server   = opts[:server]
  connection_params.instance = opts[:instance]
  connection_params.port     = opts[:port]
  connection_params.username = opts[:username]
  connection_params.password = opts[:password]
  return self
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &blk) ⇒ Object

Proxies all other method calls to the system connection See the DBIProxy for specific methods exposed



43
44
45
# File 'lib/connectator/base/connection.rb', line 43

def method_missing(method, *args, &blk)
  system_connection_proxy.send(method, *args, &blk)
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



4
5
6
# File 'lib/connectator/base/connection.rb', line 4

def error
  @error
end

Instance Method Details

#connection_paramsObject



16
17
18
# File 'lib/connectator/base/connection.rb', line 16

def connection_params
  @connection_params ||= OpenStruct.new
end

#connection_stringObject



47
48
49
# File 'lib/connectator/base/connection.rb', line 47

def connection_string
  raise 'Abstract Method'
end

#ping?Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
# File 'lib/connectator/base/connection.rb', line 24

def ping?
  if Pinger.ping?(connection_params.server, 3)
    true
  else
    @error = "Could not ping: #{connection_params.server}"
    false
  end
end

#valid?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/connectator/base/connection.rb', line 20

def valid?
  ping? && valid_system_connection?
end

#valid_system_connection?Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
39
# File 'lib/connectator/base/connection.rb', line 33

def valid_system_connection?
  system_connection_proxy.connection
  true
rescue => e
  @error = e.message
  false
end