connectator 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +16 -0
  2. data/lib/connectator/base/connection.rb +23 -13
  3. metadata +18 -2
data/README.md CHANGED
@@ -41,3 +41,19 @@ drivers.
41
41
  ## UNIX ODBC
42
42
 
43
43
  See example_odbcinst.ini for a sample of what the /etc/odbcinst.ini should look like.
44
+
45
+
46
+ ## Usage
47
+
48
+ # Initiate the connection object
49
+ c = Connectator::MySQL::Connection.new(:server => 'server.com',
50
+ :database => 'foo',
51
+ :port => '3306',
52
+ :username => 'my_user',
53
+ :password => 'secret')
54
+ # Check to see if this is a valid connection
55
+ c.valid?
56
+ # if there was an error, you can inspect
57
+ c.error
58
+ # run a select statement against the database
59
+ c.select_all('select * from 'foo.bar')
@@ -1,7 +1,7 @@
1
1
  module Connectator
2
2
  module Base
3
3
  class Connection
4
- attr_reader :connection_error
4
+ attr_reader :error
5
5
 
6
6
  def initialize(opts = {})
7
7
  raise "Connection Options are required" if opts.empty?
@@ -17,15 +17,6 @@ module Connectator
17
17
  @connection_params ||= OpenStruct.new
18
18
  end
19
19
 
20
- def system_connection
21
- @system_connection ||= Connectator::Base::DBIProxy.new(open)
22
- end
23
-
24
- # proxies all other method calls to the DBIProxy
25
- def method_missing(method, *args, &blk)
26
- system_connection.send(method, *args, &blk)
27
- end
28
-
29
20
  def valid?
30
21
  ping? && valid_system_connection?
31
22
  end
@@ -34,25 +25,44 @@ module Connectator
34
25
  if Pinger.ping?(connection_params.server, 3)
35
26
  true
36
27
  else
37
- @connection_error = "Could not ping: #{connection_params.server}"
28
+ @error = "Could not ping: #{connection_params.server}"
38
29
  false
39
30
  end
40
31
  end
41
32
 
42
33
  def valid_system_connection?
43
- system_connection.connection
34
+ system_connection_proxy.connection
44
35
  true
45
36
  rescue => e
46
- @connection_error = e.message
37
+ @error = e.message
47
38
  false
48
39
  end
40
+
41
+ # Proxies all other method calls to the system connection
42
+ # See the DBIProxy for specific methods exposed
43
+ def method_missing(method, *args, &blk)
44
+ system_connection_proxy.send(method, *args, &blk)
45
+ end
49
46
 
50
47
  def connection_string
51
48
  raise 'Abstract Method'
52
49
  end
53
50
 
54
51
  private
52
+
53
+ # TBD: not sure exactly how reload will be exposed
54
+ def system_connection_proxy(reload = false)
55
+ if reload
56
+ @system_connection_proxy = new_system_connection_proxy
57
+ else
58
+ @system_connection_proxy ||= new_system_connection_proxy
59
+ end
60
+ end
55
61
 
62
+ def new_system_connection_proxy
63
+ DBIProxy.new(open)
64
+ end
65
+
56
66
  def open
57
67
  DBI.connect(connection_string)
58
68
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: connectator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -43,6 +43,22 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: 0.2.5
46
+ - !ruby/object:Gem::Dependency
47
+ name: ruby-oci8
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
46
62
  - !ruby/object:Gem::Dependency
47
63
  name: bundler
48
64
  requirement: !ruby/object:Gem::Requirement
@@ -149,7 +165,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
149
165
  version: '0'
150
166
  segments:
151
167
  - 0
152
- hash: -707223795178079430
168
+ hash: 4490405009583718652
153
169
  required_rubygems_version: !ruby/object:Gem::Requirement
154
170
  none: false
155
171
  requirements: