sequelizer 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +34 -0
- data/README.md +6 -2
- data/lib/sequelizer/options.rb +17 -9
- data/lib/sequelizer/options_hash.rb +7 -0
- data/lib/sequelizer/version.rb +1 -1
- data/sequelizer.gemspec +1 -0
- data/test/sequelizer/test_env_config.rb +1 -0
- data/test/sequelizer/test_options.rb +37 -0
- metadata +20 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f543366458873761352e0464a1113a9c2f791c7e
|
4
|
+
data.tar.gz: 36531d0c933c330511d8e15a546e7d9cd391bffa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b6dae1e942d5ef102eaed5ba14fb98c84b827079c67ed6171d87b88620608b1a82aaf84b19e93ab3444c79fbfb1d4ce3aa7e9b52223180708abd66428bb3a7d
|
7
|
+
data.tar.gz: 29dc04d9f2e5ab95f8ea1062f039a5451acc921d65cd8d39783d1e611cb4ae95eb45d991f307c1c23dd8ea6343cd9cec8fd9a52a5a6fb10484020f454de3c1d4
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
## 0.0.2 - 2014-07-10
|
4
|
+
|
5
|
+
### Added
|
6
|
+
- This [CHANGELOG](http://keepachangelog.com/)
|
7
|
+
- Behavior to merge options from all sources (#3)
|
8
|
+
- Dependency on hashie gem
|
9
|
+
- Some tests for Sequelizer::Options
|
10
|
+
- Sequelizer::OptionsHash
|
11
|
+
- Reference to issues #1, #3 in README
|
12
|
+
|
13
|
+
### Deprecated
|
14
|
+
- Nothing.
|
15
|
+
|
16
|
+
### Removed
|
17
|
+
- Nothing.
|
18
|
+
|
19
|
+
### Fixed
|
20
|
+
- Prevented TestEnvConfig from polluting environment variables
|
21
|
+
|
22
|
+
## 0.0.1 - 2014-07-10
|
23
|
+
|
24
|
+
### Added
|
25
|
+
- The project itself
|
26
|
+
|
27
|
+
### Deprecated
|
28
|
+
- Nothing.
|
29
|
+
|
30
|
+
### Removed
|
31
|
+
- Nothing.
|
32
|
+
|
33
|
+
### Fixed
|
34
|
+
- Nothing.
|
data/README.md
CHANGED
@@ -51,13 +51,17 @@ end
|
|
51
51
|
|
52
52
|
`new_db` will create a new connection to the database on each call.
|
53
53
|
|
54
|
-
Both take a hash of database options if you don't want to create a config/database.yml or .env file, or simply wish to override those options.
|
54
|
+
Both take a hash of database options if you don't want to create a config/database.yml or .env file, or simply wish to override those options. Options are merged together from all sources with the following precedence:
|
55
|
+
|
56
|
+
passed_options > .env > manually defined environment variables > config/database.yml
|
57
|
+
|
58
|
+
So if config/database.yml specifies a connection, you can set an environment variable (either manually, or through .env) to override one of those options. Similarly, if you pass an option to the method directly, that option will override the YAML and ENV-based options. See #3 for further discussion.
|
55
59
|
|
56
60
|
Take a look at the examples directory for a few ways you can specify your database configuration options.
|
57
61
|
|
58
62
|
## Frustrations
|
59
63
|
|
60
|
-
I can't seem to figure out a way to avoid having to specify the database gem in the a user's bundler file. If anyone has ideas on how to automagically load the correct database gem based on the database options fed to Sequelizer, please let me know!
|
64
|
+
I can't seem to figure out a way to avoid having to specify the database gem in the a user's bundler file. If anyone has ideas on how to automagically load the correct database gem based on the database options fed to Sequelizer, please let me know (#1)!
|
61
65
|
|
62
66
|
## Contributing
|
63
67
|
|
data/lib/sequelizer/options.rb
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
require 'sequelizer/yaml_config'
|
2
2
|
require 'sequelizer/env_config'
|
3
|
+
require 'sequelizer/options_hash'
|
3
4
|
|
4
5
|
module Sequelizer
|
5
6
|
class Options
|
6
7
|
def initialize(options = nil)
|
7
|
-
@options = fix_options(options
|
8
|
+
@options = fix_options(options)
|
8
9
|
end
|
9
10
|
|
10
11
|
def to_hash
|
11
12
|
@options
|
12
13
|
end
|
13
14
|
|
14
|
-
%w(adapter database username password
|
15
|
+
%w(adapter database username password schema_search_path).each do |name|
|
15
16
|
define_method(name) do
|
16
17
|
@options[name]
|
17
18
|
end
|
@@ -24,13 +25,18 @@ module Sequelizer
|
|
24
25
|
#
|
25
26
|
# If fed anything, like a string that represents the URL for a DB,
|
26
27
|
# the string is returned without modification
|
27
|
-
def fix_options(
|
28
|
-
return
|
28
|
+
def fix_options(passed_options)
|
29
|
+
return passed_options unless passed_options.nil? || passed_options.is_a?(Hash)
|
30
|
+
sequelizer_options = db_config.merge((passed_options || {}).to_hash)
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
32
|
+
if sequelizer_options[:adapter] =~ /^postgres/
|
33
|
+
sequelizer_options[:adapter] = 'postgres'
|
34
|
+
paths = %w(schema_search_path search_path schema).map { |key| sequelizer_options.delete(key) }.compact
|
35
|
+
|
36
|
+
unless paths.empty?
|
37
|
+
sequelizer_options[:schema_search_path] = paths.first
|
38
|
+
sequelizer_options[:after_connect] = after_connect(paths.first)
|
39
|
+
end
|
34
40
|
end
|
35
41
|
|
36
42
|
sequelizer_options
|
@@ -41,7 +47,9 @@ module Sequelizer
|
|
41
47
|
# - environment variables (also reads from .env)
|
42
48
|
def db_config
|
43
49
|
@db_config ||= begin
|
44
|
-
YamlConfig.new.options ||
|
50
|
+
opts = OptionsHash.new(YamlConfig.new.options || {})
|
51
|
+
opts.merge!(EnvConfig.new.options || {})
|
52
|
+
opts
|
45
53
|
end
|
46
54
|
end
|
47
55
|
|
data/lib/sequelizer/version.rb
CHANGED
data/sequelizer.gemspec
CHANGED
@@ -0,0 +1,37 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
require_relative '../../lib/sequelizer/options'
|
3
|
+
|
4
|
+
|
5
|
+
class TestOptions < Minitest::Test
|
6
|
+
def test_changes_postgresql_adapter_to_postgres
|
7
|
+
options = Sequelizer::Options.new(Sequelizer::OptionsHash.new(adapter: 'postgresql'))
|
8
|
+
|
9
|
+
assert_equal('postgres', options.adapter)
|
10
|
+
assert_equal('postgres', options.to_hash[:adapter])
|
11
|
+
assert_equal('postgres', options.to_hash['adapter'])
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_finds_schema_as_search_path
|
15
|
+
options = Sequelizer::Options.new(Sequelizer::OptionsHash.new(adapter: 'postgres', search_path: 'path'))
|
16
|
+
|
17
|
+
assert_equal('path', options.schema_search_path)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_finds_schema_as_schema
|
21
|
+
options = Sequelizer::Options.new(Sequelizer::OptionsHash.new(adapter: 'postgres', schema: 'path'))
|
22
|
+
|
23
|
+
assert_equal('path', options.schema_search_path)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_finds_schema_as_schema_search_path
|
27
|
+
options = Sequelizer::Options.new(Sequelizer::OptionsHash.new(adapter: 'postgres', schema_search_path: 'path'))
|
28
|
+
|
29
|
+
assert_equal('path', options.schema_search_path)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_returns_a_hash_even_if_given_nil
|
33
|
+
options = Sequelizer::Options.new
|
34
|
+
assert_equal({}, options.to_hash)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequelizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Duryea
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0.19'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: hashie
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '3.2'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '3.2'
|
111
125
|
description: Easily establish a connection to a database via Sequel gem using options
|
112
126
|
specified in config/database.yml or .env files
|
113
127
|
email:
|
@@ -118,6 +132,7 @@ extensions: []
|
|
118
132
|
extra_rdoc_files: []
|
119
133
|
files:
|
120
134
|
- ".gitignore"
|
135
|
+
- CHANGELOG.md
|
121
136
|
- Gemfile
|
122
137
|
- Guardfile
|
123
138
|
- LICENSE.txt
|
@@ -133,12 +148,14 @@ files:
|
|
133
148
|
- lib/sequelizer/env_config.rb
|
134
149
|
- lib/sequelizer/gemfile_modifier.rb
|
135
150
|
- lib/sequelizer/options.rb
|
151
|
+
- lib/sequelizer/options_hash.rb
|
136
152
|
- lib/sequelizer/version.rb
|
137
153
|
- lib/sequelizer/yaml_config.rb
|
138
154
|
- sequelizer.gemspec
|
139
155
|
- test/sequelizer/test_connection_maker.rb
|
140
156
|
- test/sequelizer/test_env_config.rb
|
141
157
|
- test/sequelizer/test_gemfile_modifier.rb
|
158
|
+
- test/sequelizer/test_options.rb
|
142
159
|
- test/sequelizer/test_yaml_config.rb
|
143
160
|
- test/test_helper.rb
|
144
161
|
homepage: https://github.com/outcomesinsights/sequelizer
|
@@ -169,5 +186,7 @@ test_files:
|
|
169
186
|
- test/sequelizer/test_connection_maker.rb
|
170
187
|
- test/sequelizer/test_env_config.rb
|
171
188
|
- test/sequelizer/test_gemfile_modifier.rb
|
189
|
+
- test/sequelizer/test_options.rb
|
172
190
|
- test/sequelizer/test_yaml_config.rb
|
173
191
|
- test/test_helper.rb
|
192
|
+
has_rdoc:
|