connectator 0.0.7 → 0.0.8

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.
data/README.md CHANGED
@@ -1,20 +1,75 @@
1
1
  # Connectator [![Build Status](https://travis-ci.org/jamin4jc/connectator.png?branch=master)](https://travis-ci.org/jamin4jc/connectator)
2
2
 
3
- Multi-Connection proxy for DBI
3
+ Multi-System Connection Proxy Mutator
4
4
 
5
- ## Notes
5
+ ## Setup/Installation
6
6
 
7
- *This gem is currently using the older DBI gem.*
8
- https://github.com/erikh/ruby-dbi
7
+ * Connect to any system (at least theoretically). This gem is a multi-system
8
+ connection proxy. Right now the gem only supports database connections through
9
+ a fork of the ruby-dbi gem by Erik Hollensbe called connectator-dbi. This gem
10
+ is only intended to be used on UNIX/Linux type systems.
9
11
 
10
- This will at some point in the future change to use the new rdbi gem.
11
- https://github.com/RDBI/rdbi
12
+ In addition to the gem, your system needs to have unixODBC for most of the
13
+ database connections except for Oracle. FreeTDS is required for SQL Server
14
+ and Sybase. If you want to use MySQL, you will need to set up the MySQL ODBC
15
+ client. The same goes for DB2
16
+
17
+ ### System Software
18
+
19
+ #### unixODBC (http://www.unixodbc.org)
20
+
21
+ sudo apt-get install unixodbc
22
+
23
+ After installing unixODBC, you will need to set up your unixodbc.ini. This
24
+ gem expects that to use DSN-less (unnamed) configurations for systems as
25
+ opposed to specifying each system in your unixodbc.ini. There is an
26
+ example_odbcinst.ini in this project. Some of the syntax is very important.
27
+ For instance the names of each section needs to be exactly as specified,
28
+ but the location of the Driver and Setup files should match your system.
29
+ Other settings are per your discretion.
30
+
31
+ This file is generally located on your system at /etc/odbcinst.ini.
32
+
33
+ #### FreeTDS (http://freetds.schemamania.org)
34
+
35
+ FreeTDS is used as the driver for the SQL Server and Sybase Connectator.
36
+
37
+ Install the FreeTDS package if you want to use SQL Server or Syabase.
38
+ On Ubuntu this would equate to:
39
+
40
+ sudo apt-get install freetds
41
+
42
+ #### MySQL Client for ODBC
43
+
44
+ Install the MySQL client for ODBC if you want to use the MySQL Connectator.
45
+ On Ubuntu this would equate to:
46
+
47
+ sudo apt-get install libmyodbc
48
+
49
+ #### Oracle Client
50
+
51
+ Install an Oracle Client if you want to use the Oracle Connectator
52
+
53
+ To use the Oracle Connectator you will need to install some kind of Oracle
54
+ client, either the instant client or full client. There are plenty of
55
+ instructions online for setting this up, so I will not elaborate here.
56
+
57
+ #### DB2 Client
58
+
59
+ Install the DB2 client if you want to use the DB2 Connectator
60
+
61
+ ### Gem Installation
62
+
63
+ gem install connectator
64
+ gem install ruby-oci8 # optionally if you want to use Oracle
65
+
66
+ ## Connectator Systems
12
67
 
13
68
  ### Oracle
14
69
 
15
- * Uses the ruby-oci8 gem directly
16
- * Note that this gem does not directly require the ruby-oci8 gem. If you need
17
- to use Oracle, include the ruby-oci8 gem in your project.
70
+ * Uses the ruby-oci8 gem directly. Note that this gem does not directly
71
+ require the ruby-oci8 gem. If you need to use Oracle you should include the
72
+ ruby-oci8 gem in your project.
18
73
 
19
74
  ### Sql Server/Sybase
20
75
 
@@ -38,11 +93,6 @@ its drivers.
38
93
  the DB2 client. Unix ODBC will need to reference the DB2 driver as one of its
39
94
  drivers.
40
95
 
41
- ## UNIX ODBC
42
-
43
- See example_odbcinst.ini for a sample of what the /etc/odbcinst.ini should look like.
44
-
45
-
46
96
  ## Usage
47
97
 
48
98
  # Initiate the connection object
@@ -56,4 +106,4 @@ See example_odbcinst.ini for a sample of what the /etc/odbcinst.ini should look
56
106
  # if there was an error, you can inspect
57
107
  c.error
58
108
  # run a select statement against the database
59
- c.select_all('select * from 'foo.bar')
109
+ c.select_all('select * from foo.bar')
@@ -4,10 +4,10 @@ module Connectator
4
4
  include UsingDBIProxy
5
5
 
6
6
  def initialize(opts = {})
7
+ super(opts)
7
8
  connection_params.driver = 'DB2'
8
9
  connection_params.protocol = 'TCPIP'
9
10
  connection_params.database = opts[:database]
10
- super(opts)
11
11
  end
12
12
 
13
13
  def connection_string
@@ -24,17 +24,38 @@ module Connectator
24
24
  end
25
25
 
26
26
  def connection_class
27
- "Connectator::#{connectator_params.kind}::Connection".constantize
27
+ case connectator_symbol
28
+ when :db2 then Connectator::DB2::Connection
29
+ when :mysql then Connectator::MySQL::Connection
30
+ when :oracle then Connectator::Oracle::Connection
31
+ when :sql, :sql_server then Connectator::SQL::Connection
32
+ when :sybase then Connectator::Sybase::Connection
33
+ else raise "Connectator class was not found"
34
+ end
28
35
  end
29
36
 
30
37
  def extract_connectator_params
31
38
  {
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
39
+ :server => rescue_as_nil { connectator_params.server },
40
+ :instance => rescue_as_nil { connectator_params.instance },
41
+ :database => rescue_as_nil { connectator_params.database },
42
+ :port => rescue_as_nil { connectator_params.port },
43
+ :option => rescue_as_nil { connectator_params.option },
44
+ :username => rescue_as_nil { connectator_params.username },
45
+ :password => rescue_as_nil { connectator_params.password }
37
46
  }
38
47
  end
48
+
49
+ private
50
+
51
+ def connectator_symbol
52
+ rescue_as_nil { connectator_params.kind.to_s.downcase.gsub(' ','_').intern }
53
+ end
54
+
55
+ def rescue_as_nil
56
+ yield
57
+ rescue
58
+ nil
59
+ end
39
60
  end
40
61
  end
@@ -1,15 +1,16 @@
1
1
  module Connectator
2
- module Mysql
2
+ module MySQL
3
3
  class Connection < Base::Connection
4
4
  include UsingDBIProxy
5
5
 
6
6
  def initialize(opts = {})
7
+ super(opts)
7
8
  connection_params.driver = 'MySQL'
8
9
  # See this url for options flags
9
10
  # http://dev.mysql.com/doc/refman/5.0/en/connector-odbc-configuration-connection-parameters.html#codbc-dsn-option-flags
11
+ connection_params.port ||= '3306'
10
12
  connection_params.option = opts[:option] || '3'
11
- connection_params.database = opts[:database] || nil
12
- super(opts)
13
+ connection_params.database = opts[:database]
13
14
  end
14
15
 
15
16
  def connection_string
@@ -1,13 +1,13 @@
1
1
  module Connectator
2
- module Sql
2
+ module SQL
3
3
  class Connection < Base::Connection
4
4
  include UsingDBIProxy
5
5
 
6
6
  def initialize(opts = {})
7
+ super(opts)
7
8
  connection_params.driver = 'FreeTDS'
8
9
  connection_params.tds_version = opts[:tds_version] || '8.0'
9
10
  connection_params.database = opts[:database] || 'master'
10
- super(opts)
11
11
  end
12
12
 
13
13
  def connection_string
@@ -1,5 +1,5 @@
1
1
  module Connectator
2
- module Sql
2
+ module SQL
3
3
  class Connection < Base::Connection
4
4
  class ServerInstanceString
5
5
  def self.build(server, instance)
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe Connectator::Base::Connection do
4
4
 
5
5
  describe "initalized with no params" do
6
- Then { lambda { Connectator::Sql::Connection.new() }.should raise_error /Connection Options are required/ }
6
+ Then { lambda { Connectator::SQL::Connection.new() }.should raise_error /Connection Options are required/ }
7
7
  end
8
8
 
9
9
  describe "initalized with basic params" do
@@ -0,0 +1,125 @@
1
+ require 'spec_helper'
2
+
3
+ describe Connectator::Factory do
4
+
5
+ describe "a params object with an undefined kind" do
6
+ Given(:connection_params_object) { Object.new }
7
+ When(:factory) { Connectator::Factory.new(connection_params_object) }
8
+ Then { lambda { factory.connection_class }.should raise_error /not found/ }
9
+ end
10
+
11
+ describe "DB2" do
12
+ Given(:connection_params_object) { OpenStruct.new(:kind => kind) }
13
+ When(:factory) { Connectator::Factory.new(connection_params_object) }
14
+
15
+ describe "'DB2'" do
16
+ Given(:kind) { 'DB2' }
17
+ Then { factory.connection_class.should == Connectator::DB2::Connection }
18
+ end
19
+
20
+ describe "'db2'" do
21
+ Given(:kind) { 'db2' }
22
+ Then { factory.connection_class.should == Connectator::DB2::Connection }
23
+ end
24
+
25
+ describe ":db2" do
26
+ Given(:kind) { :db2 }
27
+ Then { factory.connection_class.should == Connectator::DB2::Connection }
28
+ end
29
+ end
30
+
31
+ describe "MySQL" do
32
+ Given(:connection_params_object) { OpenStruct.new(:kind => kind) }
33
+ When(:factory) { Connectator::Factory.new(connection_params_object) }
34
+
35
+ describe "'MySQL'" do
36
+ Given(:kind) { 'MySQL' }
37
+ Then { factory.connection_class.should == Connectator::MySQL::Connection }
38
+ end
39
+
40
+ describe "'mysql'" do
41
+ Given(:kind) { 'mysql' }
42
+ Then { factory.connection_class.should == Connectator::MySQL::Connection }
43
+ end
44
+
45
+ describe ":mysql" do
46
+ Given(:kind) { :mysql }
47
+ Then { factory.connection_class.should == Connectator::MySQL::Connection }
48
+ end
49
+ end
50
+
51
+ describe "Oracle" do
52
+ Given(:connection_params_object) { OpenStruct.new(:kind => kind) }
53
+ When(:factory) { Connectator::Factory.new(connection_params_object) }
54
+
55
+ describe "'Oracle'" do
56
+ Given(:kind) { 'Oracle' }
57
+ Then { factory.connection_class.should == Connectator::Oracle::Connection }
58
+ end
59
+
60
+ describe "'oracle'" do
61
+ Given(:kind) { 'oracle' }
62
+ Then { factory.connection_class.should == Connectator::Oracle::Connection }
63
+ end
64
+
65
+ describe ":oracle" do
66
+ Given(:kind) { :oracle }
67
+ Then { factory.connection_class.should == Connectator::Oracle::Connection }
68
+ end
69
+ end
70
+
71
+ describe "SQL Server" do
72
+ Given(:connection_params_object) { OpenStruct.new(:kind => kind) }
73
+ When(:factory) { Connectator::Factory.new(connection_params_object) }
74
+
75
+ describe "'SQL'" do
76
+ Given(:kind) { 'SQL' }
77
+ Then { factory.connection_class.should == Connectator::SQL::Connection }
78
+ end
79
+
80
+ describe "'SQL Server'" do
81
+ Given(:kind) { 'SQL Server' }
82
+ Then { factory.connection_class.should == Connectator::SQL::Connection }
83
+ end
84
+
85
+ describe "'Sql'" do
86
+ Given(:kind) { 'Sql' }
87
+ Then { factory.connection_class.should == Connectator::SQL::Connection }
88
+ end
89
+
90
+ describe "'sql'" do
91
+ Given(:kind) { 'sql' }
92
+ Then { factory.connection_class.should == Connectator::SQL::Connection }
93
+ end
94
+
95
+ describe ":sql" do
96
+ Given(:kind) { :sql }
97
+ Then { factory.connection_class.should == Connectator::SQL::Connection }
98
+ end
99
+
100
+ describe ":sql_server" do
101
+ Given(:kind) { :sql_server }
102
+ Then { factory.connection_class.should == Connectator::SQL::Connection }
103
+ end
104
+ end
105
+
106
+ describe "Sybase" do
107
+ Given(:connection_params_object) { OpenStruct.new(:kind => kind) }
108
+ When(:factory) { Connectator::Factory.new(connection_params_object) }
109
+
110
+ describe "'Sybase'" do
111
+ Given(:kind) { 'Sybase' }
112
+ Then { factory.connection_class.should == Connectator::Sybase::Connection }
113
+ end
114
+
115
+ describe "'sybase'" do
116
+ Given(:kind) { 'sybase' }
117
+ Then { factory.connection_class.should == Connectator::Sybase::Connection }
118
+ end
119
+
120
+ describe ":sybase" do
121
+ Given(:kind) { :sybase }
122
+ Then { factory.connection_class.should == Connectator::Sybase::Connection }
123
+ end
124
+ end
125
+ end
@@ -1,22 +1,56 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Connectator::Mysql::Connection do
3
+ describe Connectator::MySQL::Connection do
4
4
 
5
5
  describe "initalized with no params" do
6
- Then { lambda { Connectator::Mysql::Connection.new() }.should raise_error /Connection Options are required/ }
6
+ Then { lambda { Connectator::MySQL::Connection.new() }.should raise_error /Connection Options are required/ }
7
7
  end
8
8
 
9
9
  describe "initalized with basic params" do
10
10
  Given(:connection) {
11
- Connectator::Mysql::Connection.new(:server => 'Server',
12
- :port => 'Port',
11
+ Connectator::MySQL::Connection.new(:server => 'Server',
13
12
  :username => 'User',
14
13
  :password => 'Pass',
15
- :instance => 'Instance')
14
+ :port => '4040',
15
+ :instance => 'Instance',
16
+ :database => 'meh',
17
+ :option => '42')
16
18
  }
17
19
 
18
20
  Then { connection.connection_params.server.should == 'Server' }
19
- Then { connection.connection_params.port.should == 'Port' }
21
+ Then { connection.connection_params.port.should == '4040' }
22
+ Then { connection.connection_params.username.should == 'User' }
23
+ Then { connection.connection_params.password.should == 'Pass' }
24
+ Then { connection.connection_params.instance.should == 'Instance' }
25
+ Then { connection.connection_params.database.should == 'meh' }
26
+ Then { connection.connection_params.option.should == '42' }
27
+
28
+ Then { connection.connection_string.should ==
29
+ "DBI:ODBC:DRIVER=MySQL;SERVER=Server;PORT=4040;DATABASE=meh;UID=User;PWD=Pass;OPTION=42" }
30
+
31
+ Then { connection.send(:connection_params_hash).should ==
32
+ {
33
+ "DRIVER" => 'MySQL',
34
+ "SERVER" => 'Server',
35
+ "PORT" => '4040',
36
+ "DATABASE" => 'meh',
37
+ "UID" => 'User',
38
+ "PWD" => 'Pass',
39
+ "OPTION" => '42'
40
+ }
41
+ }
42
+ end
43
+
44
+ describe "initalized with missing optional params" do
45
+ Given(:connection) {
46
+ Connectator::MySQL::Connection.new(:server => 'Server',
47
+ :username => 'User',
48
+ :password => 'Pass',
49
+ :instance => 'Instance')
50
+ }
51
+
52
+ Then { connection.connection_params.server.should == 'Server' }
53
+ Then { connection.connection_params.port.should == '3306' }
20
54
  Then { connection.connection_params.username.should == 'User' }
21
55
  Then { connection.connection_params.password.should == 'Pass' }
22
56
  Then { connection.connection_params.instance.should == 'Instance' }
@@ -24,13 +58,13 @@ describe Connectator::Mysql::Connection do
24
58
  Then { connection.connection_params.option.should == '3' }
25
59
 
26
60
  Then { connection.connection_string.should ==
27
- "DBI:ODBC:DRIVER=MySQL;SERVER=Server;PORT=Port;UID=User;PWD=Pass;OPTION=3" }
61
+ "DBI:ODBC:DRIVER=MySQL;SERVER=Server;PORT=3306;UID=User;PWD=Pass;OPTION=3" }
28
62
 
29
63
  Then { connection.send(:connection_params_hash).should ==
30
64
  {
31
65
  "DRIVER" => 'MySQL',
32
66
  "SERVER" => 'Server',
33
- "PORT" => 'Port',
67
+ "PORT" => '3306',
34
68
  "DATABASE" => nil,
35
69
  "UID" => 'User',
36
70
  "PWD" => 'Pass',
@@ -1,14 +1,14 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Connectator::Sql::Connection do
3
+ describe Connectator::SQL::Connection do
4
4
 
5
5
  describe "initalized with no params" do
6
- Then { lambda { Connectator::Sql::Connection.new() }.should raise_error /Connection Options are required/ }
6
+ Then { lambda { Connectator::SQL::Connection.new() }.should raise_error /Connection Options are required/ }
7
7
  end
8
8
 
9
9
  describe "initalized with basic params" do
10
10
  Given(:connection) {
11
- Connectator::Sql::Connection.new(:server => 'Server',
11
+ Connectator::SQL::Connection.new(:server => 'Server',
12
12
  :port => 'Port',
13
13
  :username => 'User',
14
14
  :password => 'Pass',
@@ -40,25 +40,25 @@ describe Connectator::Sql::Connection do
40
40
  end
41
41
 
42
42
  describe "with no instance" do
43
- Given(:connection) { Connectator::Sql::Connection.new(:server => 'Server',
43
+ Given(:connection) { Connectator::SQL::Connection.new(:server => 'Server',
44
44
  :instance => nil) }
45
45
  Then { connection.send(:server_instance_string).should == 'Server' }
46
46
  end
47
47
 
48
48
  describe "with an instance of format X\Y" do
49
- Given(:connection) { Connectator::Sql::Connection.new(:server => 'Server',
49
+ Given(:connection) { Connectator::SQL::Connection.new(:server => 'Server',
50
50
  :instance => 'Host\Instance') }
51
51
  Then { connection.send(:server_instance_string).should == 'Server\Instance' }
52
52
  end
53
53
 
54
54
  describe "with an instance of format X\Y$Z" do
55
- Given(:connection) { Connectator::Sql::Connection.new(:server => 'Server',
55
+ Given(:connection) { Connectator::SQL::Connection.new(:server => 'Server',
56
56
  :instance => 'Host\Instance$Foo') }
57
57
  Then { connection.send(:server_instance_string).should == 'Server\Instance$Foo' }
58
58
  end
59
59
 
60
60
  describe "with an instance of format X\Y_Z" do
61
- Given(:connection) { Connectator::Sql::Connection.new(:server => 'Server',
61
+ Given(:connection) { Connectator::SQL::Connection.new(:server => 'Server',
62
62
  :instance => 'Host\Instance_Foo') }
63
63
  Then { connection.send(:server_instance_string).should == 'Server\Instance_Foo' }
64
64
  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.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-15 00:00:00.000000000 Z
12
+ date: 2013-03-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dbi
@@ -131,6 +131,7 @@ files:
131
131
  - spec/connectator/pinger_spec.rb
132
132
  - spec/connectator/base/connection_spec.rb
133
133
  - spec/connectator/db2/connection_spec.rb
134
+ - spec/connectator/factory_spec.rb
134
135
  - spec/connectator/sybase/connection_spec.rb
135
136
  - spec/connectator/mysql/connection_spec.rb
136
137
  - spec/connectator/sql/connection_spec.rb
@@ -150,7 +151,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
150
151
  version: '0'
151
152
  segments:
152
153
  - 0
153
- hash: 3410537790936780615
154
+ hash: -3195616566247278493
154
155
  required_rubygems_version: !ruby/object:Gem::Requirement
155
156
  none: false
156
157
  requirements: