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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6628c636f7aee3fc9ffc3c36b9877167756c2cc0
4
- data.tar.gz: b24750aba87b1a882ee81dd18d0ec078deab4e9c
3
+ metadata.gz: f543366458873761352e0464a1113a9c2f791c7e
4
+ data.tar.gz: 36531d0c933c330511d8e15a546e7d9cd391bffa
5
5
  SHA512:
6
- metadata.gz: 986d3122766c0f9cac14bba4196469edc93d4c32718a716ae93e823898a84b35d7117d8c70d341f203c98d850cd83ceaa5867e57dab45ff5682e5a01bb405eec
7
- data.tar.gz: cd2f304548d984e8d4229350bee9b8328f2bc7193b30c4b73c4d14c2dc90bc3a955d8349855b45c8f3eadd291a613f7b587efaf9446e6220ba9fa64490df9fa4
6
+ metadata.gz: 8b6dae1e942d5ef102eaed5ba14fb98c84b827079c67ed6171d87b88620608b1a82aaf84b19e93ab3444c79fbfb1d4ce3aa7e9b52223180708abd66428bb3a7d
7
+ data.tar.gz: 29dc04d9f2e5ab95f8ea1062f039a5451acc921d65cd8d39783d1e611cb4ae95eb45d991f307c1c23dd8ea6343cd9cec8fd9a52a5a6fb10484020f454de3c1d4
@@ -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. The options you pass in aren't merged against any other configuration files you might have set up.
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
 
@@ -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 || db_config)
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 search_path).each do |name|
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(sequelizer_options)
28
- return sequelizer_options unless sequelizer_options.is_a?(Hash)
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
- search_path = sequelizer_options['search_path'] || sequelizer_options['schema_search_path']
31
- sequelizer_options['adapter'] = 'postgres' if sequelizer_options['adapter'] =~ /^postgres/
32
- if search_path && sequelizer_options['adapter'] =~ /postgres/i
33
- sequelizer_options['after_connect'] = after_connect(search_path)
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 || EnvConfig.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
 
@@ -0,0 +1,7 @@
1
+ require 'hashie'
2
+ module Sequelizer
3
+ class OptionsHash < Hash
4
+ include Hashie::Extensions::IndifferentAccess
5
+ include Hashie::Extensions::MergeInitializer
6
+ end
7
+ end
@@ -1,4 +1,4 @@
1
1
  module Sequelizer
2
2
  # Version for the gem
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
@@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
25
25
  spec.add_dependency 'sequel', '~> 4.12'
26
26
  spec.add_dependency 'dotenv', '~> 0.11'
27
27
  spec.add_dependency 'thor', '~> 0.19'
28
+ spec.add_dependency 'hashie', '~> 3.2'
28
29
  end
@@ -18,5 +18,6 @@ class TestEnvConfig < Minitest::Test
18
18
  def test_converts_sequelizer_vars_to_options
19
19
  ENV['SEQUELIZER_ADAPTER'] = 'sqlite'
20
20
  assert_equal({ 'adapter' => 'sqlite' }, @env_config.options)
21
+ ENV.delete('SEQUELIZER_ADAPTER')
21
22
  end
22
23
  end
@@ -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.1
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: