Class: Connectator::Base::Connection
- Inherits:
-
Object
- Object
- Connectator::Base::Connection
- Defined in:
- lib/connectator/base/connection.rb
Direct Known Subclasses
DB2::Connection, MySQL::Connection, Oracle::Connection, SQL::Connection, Sybase::Connection
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
Instance Method Summary collapse
- #connection_params ⇒ Object
- #connection_string ⇒ Object
-
#initialize(opts = {}) ⇒ Connection
constructor
A new instance of Connection.
-
#method_missing(method, *args, &blk) ⇒ Object
Proxies all other method calls to the system connection See the DBIProxy for specific methods exposed.
- #ping? ⇒ Boolean
- #valid? ⇒ Boolean
- #valid_system_connection? ⇒ Boolean
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
#error ⇒ Object (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_params ⇒ Object
16 17 18 |
# File 'lib/connectator/base/connection.rb', line 16 def connection_params @connection_params ||= OpenStruct.new end |
#connection_string ⇒ Object
47 48 49 |
# File 'lib/connectator/base/connection.rb', line 47 def connection_string raise 'Abstract Method' end |
#ping? ⇒ 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
20 21 22 |
# File 'lib/connectator/base/connection.rb', line 20 def valid? ping? && valid_system_connection? end |
#valid_system_connection? ⇒ 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. false end |