sequelizer 0.0.5 → 0.0.6

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: f0e093599e70651e91335650ab1356e697c514ee
4
- data.tar.gz: b46f6b86d1fe965767ed5c2a117631c44ff4ae07
3
+ metadata.gz: 0efeede798cbe0762a40b9e46a4a65da61a6c12c
4
+ data.tar.gz: ca6bb26204613c27fc29e20f7c5111de3a754621
5
5
  SHA512:
6
- metadata.gz: 248907aecabe87161db1b2a4ce3c3ee2a917cecb8436d995ca26653e2838bedecd770731189ab01b150c48d9f12ff122290c60432f458daede237547d32154a9
7
- data.tar.gz: 8584066aec604be6eee2f22411bb12df2d72a350218727dab1f0a0108a8395325ed8f8db5acd1a85c4936fb1846713139bc0707fa6aa6cc90d46a46eb9ec2ce6
6
+ metadata.gz: 082275d6849a28d57325d50045b15d6e62427ad3460ea3c7d15676bf48948b03ecdd23e4fb67aa5b36220cd22504adf89ec12c9104631a7dc147850307388fc3
7
+ data.tar.gz: 206f9f517384d3530c3a326c2a5c8a183ca183869b34039bcade3718879196274447768cee6ef85afaf46ab6792b35ccbf914973749b0ccef0c63eba041f641f
@@ -1,6 +1,36 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## Unreleased
5
+
6
+ ### Added
7
+ - Nothing.
8
+
9
+ ### Deprecated
10
+ - Nothing.
11
+
12
+ ### Removed
13
+ - Nothing.
14
+
15
+ ### Fixed
16
+ - Nothing.
17
+
18
+ ## 0.0.6 - 2015-08-21
19
+
20
+ ### Added
21
+ - Support for ruby-oci8 (Oracle) in update_gemfile command
22
+ - Read user-level configuration from ~/.config/sequelizer/database.yml
23
+
24
+ ### Deprecated
25
+ - Nothing.
26
+
27
+ ### Removed
28
+ - Nothing.
29
+
30
+ ### Fixed
31
+ - Bug where options passed as symbols where sometimes ignored.
32
+
33
+
4
34
  ## 0.0.5 - 2014-08-29
5
35
 
6
36
  ### Added
data/README.md CHANGED
@@ -61,7 +61,7 @@ end
61
61
 
62
62
  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:
63
63
 
64
- passed_options > .env > manually defined environment variables > config/database.yml
64
+ passed_options > .env > manually defined environment variables > config/database.yml > ~/.config/sequelizer/database.yml
65
65
 
66
66
  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.
67
67
 
@@ -14,7 +14,7 @@ module Sequelizer
14
14
  config[new_key] = ENV[key]
15
15
  config
16
16
  end
17
- env_config.empty? ? nil : env_config
17
+ env_config.empty? ? {} : env_config
18
18
  end
19
19
  end
20
20
  end
@@ -38,6 +38,8 @@ module Sequelizer
38
38
  'mysql2'
39
39
  when 'tinytds'
40
40
  'tiny_tds'
41
+ when 'oracle'
42
+ 'ruby-oci8'
41
43
  when nil
42
44
  raise "No database adapter defined in your Sequelizer configuration"
43
45
  else
@@ -27,7 +27,7 @@ module Sequelizer
27
27
  # the string is returned without modification
28
28
  def fix_options(passed_options)
29
29
  return passed_options unless passed_options.nil? || passed_options.is_a?(Hash)
30
- sequelizer_options = db_config.merge((passed_options || {}).to_hash)
30
+ sequelizer_options = db_config.merge(OptionsHash.new(passed_options || {}).to_hash)
31
31
 
32
32
  if sequelizer_options[:adapter] =~ /^postgres/
33
33
  sequelizer_options[:adapter] = 'postgres'
@@ -50,12 +50,14 @@ module Sequelizer
50
50
  end
51
51
 
52
52
  # Grabs the database options from
53
+ # - ~/.config/sequelizer.yml if it exists
53
54
  # - config/database.yml if it exists
54
55
  # - environment variables (also reads from .env)
55
56
  def db_config
56
57
  @db_config ||= begin
57
- opts = OptionsHash.new(YamlConfig.new.options || {})
58
- opts.merge!(EnvConfig.new.options || {})
58
+ opts = OptionsHash.new(YamlConfig.user_config.options)
59
+ opts.merge!(YamlConfig.local_config.options)
60
+ opts.merge!(EnvConfig.new.options)
59
61
  opts
60
62
  end
61
63
  end
@@ -1,4 +1,4 @@
1
1
  module Sequelizer
2
2
  # Version for the gem
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.6"
4
4
  end
@@ -1,12 +1,33 @@
1
1
  require 'psych'
2
+ require 'pathname'
2
3
 
3
4
  module Sequelizer
4
5
  class YamlConfig
6
+ attr_reader :config_file_path
7
+
8
+ class << self
9
+ def local_config
10
+ new
11
+ end
12
+
13
+ def user_config
14
+ new(user_config_path)
15
+ end
16
+
17
+ def user_config_path
18
+ Pathname.new("~") + ".config" + "sequelizer" + "database.yml"
19
+ end
20
+ end
21
+
22
+ def initialize(config_file_path = nil)
23
+ @config_file_path = Pathname.new(config_file_path || Pathname.pwd + "config" + "database.yml").expand_path
24
+ end
25
+
5
26
  # Returns a set of options pulled from config/database.yml
6
27
  # or +nil+ if config/database.yml doesn't exist
7
28
  def options
8
- return nil unless config_file.exist?
9
- config['adapter'] ? config : config[environment]
29
+ return {} unless config_file_path.exist?
30
+ config['adapter'] || config[:adapter] ? config : config[environment]
10
31
  end
11
32
 
12
33
  # The environment to load from database.yml
@@ -24,21 +45,9 @@ module Sequelizer
24
45
 
25
46
  private
26
47
 
27
- # The Pathname to config/database.yml
28
- def config_file
29
- @config_file ||= begin
30
- root + 'config' + 'database.yml'
31
- end
32
- end
33
-
34
- # The root directory to search for config/database.yml
35
- def root
36
- @root ||= Pathname.pwd
37
- end
38
-
39
48
  # The config as read from config/database.yml
40
49
  def config
41
- @config ||= Psych.load_file(config_file)
50
+ @config ||= Psych.load_file(config_file_path)
42
51
  end
43
52
  end
44
53
  end
@@ -15,12 +15,15 @@ class TestConnectionMaker < Minitest::Test
15
15
  end
16
16
 
17
17
  def test_accepts_options_as_params
18
- assert_equal :connection, Sequelizer::ConnectionMaker.new(@options).connection
18
+ Sequelizer::YamlConfig.stub :user_config_path, Pathname.new('/completely/made/up/path/that/does/not/exist') do
19
+ assert_equal :connection, Sequelizer::ConnectionMaker.new(@options).connection
20
+ end
19
21
  end
20
22
 
21
23
  def test_reads_options_from_yaml_config
22
24
  yaml_config = Minitest::Mock.new
23
25
  yaml_config.expect :options, @options
26
+ yaml_config.expect :options, @options
24
27
 
25
28
  Sequelizer::YamlConfig.stub :new, yaml_config do
26
29
  assert_equal :connection, Sequelizer::ConnectionMaker.new.connection
@@ -31,7 +34,8 @@ class TestConnectionMaker < Minitest::Test
31
34
 
32
35
  def test_reads_options_from_env_config_if_no_yaml_config
33
36
  yaml_config = Minitest::Mock.new
34
- yaml_config.expect :options, nil
37
+ yaml_config.expect :options, {}
38
+ yaml_config.expect :options, {}
35
39
 
36
40
  env_config = Minitest::Mock.new
37
41
  env_config.expect :options, @options
@@ -6,6 +6,7 @@ class TestEnvConfig < Minitest::Test
6
6
  def setup
7
7
  @env_config = Sequelizer::EnvConfig.new
8
8
  end
9
+
9
10
  def test_loads_dotenv
10
11
  mock = Minitest::Mock.new
11
12
  stub_const(Sequelizer::EnvConfig, :Dotenv, mock) do
@@ -15,6 +16,10 @@ class TestEnvConfig < Minitest::Test
15
16
  end
16
17
  end
17
18
 
19
+ def test_options_default_to_empty_hash
20
+ assert_equal(@env_config.options, {})
21
+ end
22
+
18
23
  def test_converts_sequelizer_vars_to_options
19
24
  ENV['SEQUELIZER_ADAPTER'] = 'sqlite'
20
25
  assert_equal({ 'adapter' => 'sqlite' }, @env_config.options)
@@ -41,8 +41,15 @@ class TestOptions < Minitest::Test
41
41
  end
42
42
 
43
43
  def test_returns_a_hash_even_if_given_nil
44
- options = Sequelizer::Options.new
45
- assert_equal({}, options.to_hash)
44
+ Sequelizer::YamlConfig.stub :user_config_path, Pathname.new('/completely/made/up/path/that/does/not/exist') do
45
+ options = Sequelizer::Options.new
46
+ assert_equal({}, options.to_hash)
47
+ end
48
+ end
49
+
50
+ def test_handles_symbolized_search_path
51
+ options = Sequelizer::Options.new(search_path: 'passed', adapter: 'postgres')
52
+ assert_equal 'passed', options.search_path
46
53
  end
47
54
  end
48
55
 
@@ -15,7 +15,7 @@ class TestYamlConfig < Minitest::Test
15
15
  mock.expect :load_file, { 'adapter' => 'sqlite' }, [file_mock]
16
16
  file_mock.expect :exist?, true
17
17
 
18
- @yaml_config.stub :config_file, file_mock do
18
+ @yaml_config.stub :config_file_path, file_mock do
19
19
  assert_equal({ 'adapter' => 'sqlite' }, @yaml_config.options)
20
20
  end
21
21
 
@@ -27,7 +27,7 @@ class TestYamlConfig < Minitest::Test
27
27
  def test_loads_by_environment_if_present
28
28
  file_mock = Minitest::Mock.new
29
29
  file_mock.expect :exist?, true
30
- @yaml_config.stub :config_file, file_mock do
30
+ @yaml_config.stub :config_file_path, file_mock do
31
31
  @yaml_config.stub :config, {'development' => { 'adapter' => 'sqlite' }} do
32
32
  assert_equal({ 'adapter' => 'sqlite' }, @yaml_config.options)
33
33
  end
@@ -35,6 +35,30 @@ class TestYamlConfig < Minitest::Test
35
35
  file_mock.verify
36
36
  end
37
37
 
38
+ def test_options_default_to_empty_hash
39
+ assert_equal(@yaml_config.options, {})
40
+ end
41
+
42
+ def test_path_defaults_to_local_config
43
+ assert_equal(@yaml_config.config_file_path, Pathname.pwd + "config" + "database.yml")
44
+ end
45
+
46
+ def test_path_can_be_fed_pathanem_from_initialize
47
+ assert_equal(Sequelizer::YamlConfig.new(Pathname.new("~") + ".config").config_file_path, Pathname.new("~").expand_path + ".config")
48
+ end
49
+
50
+ def test_path_can_be_fed_string_from_initialize
51
+ assert_equal(Sequelizer::YamlConfig.new("~/.config").config_file_path, Pathname.new("~").expand_path + ".config")
52
+ end
53
+
54
+ def test_local_is_current_directory
55
+ assert_equal(Sequelizer::YamlConfig.local_config.config_file_path, Pathname.pwd + "config" + "database.yml")
56
+ end
57
+
58
+ def test_home_uses_home_directory
59
+ assert_equal(Sequelizer::YamlConfig.user_config.config_file_path, Pathname.new("~").expand_path + ".config" + "sequelizer" + "database.yml")
60
+ end
61
+
38
62
  def test_environment_checks_environment_variables
39
63
  env_mock = Minitest::Mock.new
40
64
  env_mock.expect :[], nil, ['SEQUELIZER_ENV']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequelizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Duryea
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-29 00:00:00.000000000 Z
11
+ date: 2015-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -178,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
178
178
  version: '0'
179
179
  requirements: []
180
180
  rubyforge_project:
181
- rubygems_version: 2.2.2
181
+ rubygems_version: 2.4.6
182
182
  signing_key:
183
183
  specification_version: 4
184
184
  summary: Sequel database connections via config/database.yml or .env