connectator 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,75 @@
1
+ require 'ostruct'
2
+
3
+ module Connectator
4
+ module Base
5
+ class Connection
6
+ attr_reader :connection_error
7
+
8
+ def initialize(opts = {})
9
+ raise "Connection Options are required" if opts.empty?
10
+ connection_params.server = opts[:server]
11
+ connection_params.instance = opts[:instance]
12
+ connection_params.port = opts[:port]
13
+ connection_params.username = opts[:username]
14
+ connection_params.password = opts[:password]
15
+ return self
16
+ end
17
+
18
+ def connection_params
19
+ @connection_params ||= OpenStruct.new
20
+ end
21
+
22
+ def dbi
23
+ @dbi ||= open
24
+ end
25
+
26
+ def close
27
+ dbi.disconnect
28
+ end
29
+
30
+ def valid?
31
+ ping? && valid_dbi?
32
+ end
33
+
34
+ def ping?
35
+ if Pinger.pong?(connection_params.server, 3)
36
+ true
37
+ else
38
+ @connection_error = "Could not ping: #{connection_params.server}"
39
+ false
40
+ end
41
+ end
42
+
43
+ def valid_dbi?
44
+ dbi
45
+ true
46
+ rescue DBI::DatabaseError => e
47
+ @connection_error = e.message
48
+ false
49
+ end
50
+
51
+ def method_missing(method, *args, &blk)
52
+ puts method
53
+ dbi.send(method, *args, &blk)
54
+ end
55
+
56
+ def connection_string
57
+ raise 'Abstract Method'
58
+ end
59
+
60
+ private
61
+
62
+ def open
63
+ DBI.connect(connection_string)
64
+ end
65
+
66
+ def connection_params_list
67
+ connection_params_hash.map { |k,v| "#{k}=#{v}"}.join(';')
68
+ end
69
+
70
+ def connection_params_hash
71
+ raise 'Abstract Method'
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,31 @@
1
+ module Connectator
2
+ module DB2
3
+ class Connection < Base::Connection
4
+
5
+ def initialize(opts = {})
6
+ connection_params.database = opts[:database]
7
+ connection_params.driver = 'DB2'
8
+ connection_params.protocol = 'TCPIP'
9
+ super(opts)
10
+ end
11
+
12
+ def connection_string
13
+ "DBI:ODBC:#{connection_params_list}"
14
+ end
15
+
16
+ private
17
+
18
+ def connection_params_hash
19
+ {
20
+ "DRIVER" => connection_params.driver,
21
+ "PROTOCOL" => connection_params.protocol,
22
+ "HOSTNAME" => connection_params.server,
23
+ "Port" => connection_params.port,
24
+ "DATABASE" => connection_params.database,
25
+ "UID" => connection_params.username,
26
+ "PWD" => connection_params.password
27
+ }
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,40 @@
1
+ module Connectator
2
+ class Factory
3
+
4
+ # connectator_params object must respond to:
5
+ # * kind (Oracle, Sql, Sybase, DB2)
6
+ # * server
7
+ # * instance
8
+ # * port
9
+ # * username
10
+ # * password
11
+ #
12
+ def self.build(connectator_params)
13
+ return self.new(connectator_params).connection
14
+ end
15
+
16
+ attr_reader :connectator_params
17
+
18
+ def initialize(connectator_params)
19
+ @connectator_params = connectator_params
20
+ end
21
+
22
+ def connection(additional_params = {})
23
+ connection_class.new(extract_connectator_params.merge(additional_params))
24
+ end
25
+
26
+ def connection_class
27
+ "Connectator::#{connectator_params.kind}::Connection".constantize
28
+ end
29
+
30
+ def extract_connectator_params
31
+ {
32
+ :server => connectator_params.server,
33
+ :instance => connectator_params.instance,
34
+ :port => connectator_params.port,
35
+ :username => connectator_params.username,
36
+ :password => connectator_params.password
37
+ }
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,20 @@
1
+ module Connectator
2
+ module Oracle
3
+ class Connection < Base::Connection
4
+
5
+ def connection_string
6
+ "DBI:OCI8://#{connection_params.server}:#{connection_params.port}/#{connection_params.instance}"
7
+ end
8
+
9
+ private
10
+
11
+ # This is overrides the Base open method, because username and password
12
+ # are passed in through the DBI OCI8 driver
13
+ def open
14
+ DBI.connect(connection_string,
15
+ connection_params.username,
16
+ connection_params.password)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,30 @@
1
+ module Connectator
2
+ module Sql
3
+ class Connection < Base::Connection
4
+ class ServerInstanceString
5
+ def self.build(server, instance)
6
+ new(server, instance).server_string
7
+ end
8
+
9
+ def initialize(server, instance)
10
+ @server = server
11
+ @instance = instance
12
+ end
13
+
14
+ def server_string
15
+ "#{@server}#{server_instance}"
16
+ end
17
+
18
+ private
19
+
20
+ def server_instance
21
+ "\\#{instance_name}" unless instance_name.to_s.strip.empty?
22
+ end
23
+
24
+ def instance_name
25
+ @instance =~ /\w+\\([\w\$]+)$/; $1
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,35 @@
1
+ module Connectator
2
+ module Sql
3
+ class Connection < Base::Connection
4
+
5
+ def initialize(opts = {})
6
+ connection_params.tds_version = '8.0'
7
+ connection_params.database = 'master'
8
+ connection_params.driver = 'FreeTDS'
9
+ super(opts)
10
+ end
11
+
12
+ def connection_string
13
+ "DBI:ODBC:#{connection_params_list}"
14
+ end
15
+
16
+ private
17
+
18
+ def server_instance_string
19
+ ServerInstanceString.build(connection_params.server, connection_params.instance)
20
+ end
21
+
22
+ def connection_params_hash
23
+ {
24
+ "DRIVER" => connection_params.driver,
25
+ "TDS_Version" => connection_params.tds_version,
26
+ "SERVER" => server_instance_string,
27
+ "Port" => connection_params.port,
28
+ "DATABASE" => connection_params.database,
29
+ "UID" => connection_params.username,
30
+ "PWD" => connection_params.password
31
+ }
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,31 @@
1
+ module Connectator
2
+ module Sybase
3
+ class Connection < Base::Connection
4
+
5
+ def initialize(opts = {})
6
+ connection_params.tds_version = '5.0'
7
+ connection_params.database = 'master'
8
+ connection_params.driver = 'FreeTDS'
9
+ super(opts)
10
+ end
11
+
12
+ def connection_string
13
+ "DBI:ODBC:#{connection_params_list}"
14
+ end
15
+
16
+ private
17
+
18
+ def connection_params_hash
19
+ {
20
+ "DRIVER" => connection_params.driver,
21
+ "TDS_Version" => connection_params.tds_version,
22
+ "SERVER" => connection_params.server,
23
+ "Port" => connection_params.port,
24
+ "DATABASE" => connection_params.database,
25
+ "UID" => connection_params.username,
26
+ "PWD" => connection_params.password
27
+ }
28
+ end
29
+ end
30
+ end
31
+ end
metadata CHANGED
@@ -1,78 +1,105 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: connectator
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.1
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Benjamin Wagaman
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2013-02-14 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2013-02-14 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
15
22
  name: dbi
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: 0.4.5
22
- type: :runtime
23
23
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 5
30
+ segments:
31
+ - 0
32
+ - 4
33
+ - 5
29
34
  version: 0.4.5
30
- - !ruby/object:Gem::Dependency
31
- name: dbd-odbc
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: 0.2.5
38
35
  type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: dbd-odbc
39
39
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
41
  none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 29
46
+ segments:
47
+ - 0
48
+ - 2
49
+ - 5
45
50
  version: 0.2.5
46
- description: This gem lets you make connections to multiple kinds of DBMS systems
47
- through DBI
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ description: This gem lets you make connections to multiple kinds of DBMS systems through DBI
48
54
  email: ben@wagaman.org
49
55
  executables: []
56
+
50
57
  extensions: []
58
+
51
59
  extra_rdoc_files: []
52
- files:
60
+
61
+ files:
53
62
  - lib/connectator.rb
63
+ - lib/connectator/factory.rb
64
+ - lib/connectator/oracle/connection.rb
65
+ - lib/connectator/base/connection.rb
66
+ - lib/connectator/db2/connection.rb
67
+ - lib/connectator/sybase/connection.rb
68
+ - lib/connectator/sql/connection.rb
69
+ - lib/connectator/sql/connection/server_instance_string.rb
70
+ has_rdoc: true
54
71
  homepage: http://rubygems.org/gems/connecator
55
72
  licenses: []
73
+
56
74
  post_install_message:
57
75
  rdoc_options: []
58
- require_paths:
76
+
77
+ require_paths:
59
78
  - lib
60
- required_ruby_version: !ruby/object:Gem::Requirement
79
+ required_ruby_version: !ruby/object:Gem::Requirement
61
80
  none: false
62
- requirements:
63
- - - ! '>='
64
- - !ruby/object:Gem::Version
65
- version: '0'
66
- required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: 3
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
89
  none: false
68
- requirements:
69
- - - ! '>='
70
- - !ruby/object:Gem::Version
71
- version: '0'
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ hash: 3
94
+ segments:
95
+ - 0
96
+ version: "0"
72
97
  requirements: []
98
+
73
99
  rubyforge_project:
74
- rubygems_version: 1.8.24
100
+ rubygems_version: 1.5.3
75
101
  signing_key:
76
102
  specification_version: 3
77
103
  summary: Multi DBMS connection abstraction
78
104
  test_files: []
105
+