active_connection 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8e76425f4f8131329cb5c4b4af65887bb3447c41
4
+ data.tar.gz: af2ef1c39c02c366edf0a7920b34190a46b683e4
5
+ SHA512:
6
+ metadata.gz: 707d390ff1fa68aace50b5475ff5b1464bc758522d2f2cffbb69ef5eb7df05bf558e111bafbd58bd2c3b6560027d594093400de103c973611890db97fa08572c
7
+ data.tar.gz: ed3cb1858c028737575da457ac3f347453ed255031f143ae1e6350af7ac9c65be122b108087bf365f183f557b3cceec76c2d074a857de8e979718f289235b987
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,2 @@
1
+ rvm:
2
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in active_connection.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Frank J. Mattia
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ [![Code Climate](https://codeclimate.com/repos/52c08442e30ba01f880060b4/badges/c2bac2dcd240649516e4/gpa.png)](https://codeclimate.com/repos/52c08442e30ba01f880060b4/feed)
2
+ [![Build Status](https://travis-ci.org/frankjmattia/active_connection.png?branch=master)](https://travis-ci.org/frankjmattia/active_connection)
3
+ [![Coverage Status](https://coveralls.io/repos/frankjmattia/active_connection/badge.png?branch=master)](https://coveralls.io/r/frankjmattia/active_connection?branch=master)
4
+ [![Dependency Status](https://gemnasium.com/frankjmattia/active_connection.png)](https://gemnasium.com/frankjmattia/active_connection)
5
+
6
+ # ActiveConnection
7
+
8
+ ActiveConnection is a simple wrapper around ActiveRecord::Base.connection.schema_search_path.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'active_connection'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ ## Usage
21
+
22
+ Useful in multi-tenant situations where you have a user table in the public schema and a separate schema for each tenants data.
23
+
24
+ ```ruby
25
+ ActiveConnection.schema_search_path('other_schema', 'public') do
26
+ # Do something that depends on other_schema
27
+ end
28
+ ```
29
+
30
+ ## Contributing
31
+
32
+ 1. Fork it
33
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
34
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
35
+ 4. Push to the branch (`git push origin my-new-feature`)
36
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'active_connection/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'active_connection'
8
+ spec.version = ActiveConnection::VERSION
9
+ spec.authors = [ 'Frank J. Mattia' ]
10
+ spec.email = [ 'frankjmattia@gmail.com' ]
11
+ spec.description = %q{Scope ActiveRecord connection to specifc PostgreSQL schemata on the fly.}
12
+ spec.summary = %q{A simple wrapper around ActiveRecord::Base.connection.schema_search_path.}
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = [ 'lib' ]
20
+
21
+ spec.add_dependency 'activerecord', '>= 3.0', '< 4.1'
22
+ spec.add_dependency 'pg', '~> 0.17'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.3'
25
+ spec.add_development_dependency 'coveralls'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'rspec', '~> 2.0'
28
+ end
@@ -0,0 +1,13 @@
1
+ require 'active_connection/version'
2
+
3
+ module ActiveConnection
4
+ class << self
5
+ def schema_search_path(*paths, &block)
6
+ original_search_path = ActiveRecord::Base.connection.schema_search_path
7
+ ActiveRecord::Base.connection.schema_search_path = paths.join(',')
8
+ yield
9
+ ensure
10
+ ActiveRecord::Base.connection.schema_search_path = original_search_path
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module ActiveConnection
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+ require 'active_record'
3
+
4
+ describe ActiveConnection do
5
+ before(:all) do
6
+ PG_SPEC = {
7
+ adapter: 'postgresql',
8
+ host: 'localhost',
9
+ database: 'schema_test'
10
+ }
11
+
12
+ ActiveRecord::Base.establish_connection(PG_SPEC.merge(database: 'postgres'))
13
+ ActiveRecord::Base.connection.drop_database('schema_test')
14
+ ActiveRecord::Base.connection.create_database('schema_test')
15
+ ActiveRecord::Base.establish_connection(PG_SPEC)
16
+ ActiveRecord::Base.connection.create_schema('nonsense')
17
+ end
18
+
19
+ it 'changes the schema search path inside the block' do
20
+ ActiveConnection.schema_search_path('nonsense') do
21
+ expect(ActiveRecord::Base.connection.schema_search_path).to eq('nonsense')
22
+ end
23
+ end
24
+
25
+ it 'resets the schema search path after the block has executed' do
26
+ original_search_path = ActiveRecord::Base.connection.schema_search_path
27
+
28
+ ActiveConnection.schema_search_path('nonsense') { }
29
+
30
+ expect(ActiveRecord::Base.connection.schema_search_path).to eq(original_search_path)
31
+ end
32
+
33
+ it 'resets the schema search path after an error has occurred' do
34
+ original_search_path = ActiveRecord::Base.connection.schema_search_path
35
+ ActiveConnection.schema_search_path('nonsense') { break }
36
+
37
+ expect(ActiveRecord::Base.connection.schema_search_path).to eq(original_search_path)
38
+ end
39
+ end
@@ -0,0 +1,4 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ require 'active_connection'
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_connection
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Frank J. Mattia
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ - - <
21
+ - !ruby/object:Gem::Version
22
+ version: '4.1'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - - <
31
+ - !ruby/object:Gem::Version
32
+ version: '4.1'
33
+ - !ruby/object:Gem::Dependency
34
+ name: pg
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ~>
38
+ - !ruby/object:Gem::Version
39
+ version: '0.17'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: '0.17'
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.3'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ version: '1.3'
61
+ - !ruby/object:Gem::Dependency
62
+ name: coveralls
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rake
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ~>
80
+ - !ruby/object:Gem::Version
81
+ version: '10.0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ~>
87
+ - !ruby/object:Gem::Version
88
+ version: '10.0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rspec
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ~>
94
+ - !ruby/object:Gem::Version
95
+ version: '2.0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ~>
101
+ - !ruby/object:Gem::Version
102
+ version: '2.0'
103
+ description: Scope ActiveRecord connection to specifc PostgreSQL schemata on the fly.
104
+ email:
105
+ - frankjmattia@gmail.com
106
+ executables: []
107
+ extensions: []
108
+ extra_rdoc_files: []
109
+ files:
110
+ - .gitignore
111
+ - .rspec
112
+ - .travis.yml
113
+ - Gemfile
114
+ - LICENSE.txt
115
+ - README.md
116
+ - Rakefile
117
+ - active_connection.gemspec
118
+ - lib/active_connection.rb
119
+ - lib/active_connection/version.rb
120
+ - spec/active_connection_spec.rb
121
+ - spec/spec_helper.rb
122
+ homepage: ''
123
+ licenses:
124
+ - MIT
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 2.1.9
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: A simple wrapper around ActiveRecord::Base.connection.schema_search_path.
146
+ test_files:
147
+ - spec/active_connection_spec.rb
148
+ - spec/spec_helper.rb