sequelizer 0.0.6 → 0.1.0

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: 0efeede798cbe0762a40b9e46a4a65da61a6c12c
4
- data.tar.gz: ca6bb26204613c27fc29e20f7c5111de3a754621
3
+ metadata.gz: 8d676f724540c01e7cbd2bc6b2a354d78a2e9d15
4
+ data.tar.gz: e6872a70bdf5d268687f667273edced41abd13aa
5
5
  SHA512:
6
- metadata.gz: 082275d6849a28d57325d50045b15d6e62427ad3460ea3c7d15676bf48948b03ecdd23e4fb67aa5b36220cd22504adf89ec12c9104631a7dc147850307388fc3
7
- data.tar.gz: 206f9f517384d3530c3a326c2a5c8a183ca183869b34039bcade3718879196274447768cee6ef85afaf46ab6792b35ccbf914973749b0ccef0c63eba041f641f
6
+ metadata.gz: 8fb25153b51b05926e5da76fd977f88b8b3077b9dccedb6282edd40486bea4bc1d1e6be70fd8a576f2102a80c406663b40ef396a6ad32897730fd510cd6bddcd
7
+ data.tar.gz: ace9f653827f44fac941f1bbd6b2e6e854d3128bcf8d3a8f14343304b5f7350f2e6efe1c7ee11271cd3aa6f8f659bd6dd7b19145223372a3eecac56ac33aa4e7
@@ -1,82 +1,47 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- ## Unreleased
4
+ ## [0.1.0] - 2016-11-08
5
5
 
6
6
  ### Added
7
- - Nothing.
7
+ - Connections are cached by options to avoid over-allocation
8
+ - URL or URI option represent connection string
9
+ - sequelizer.yml is passed through ERB
8
10
 
9
- ### Deprecated
10
- - Nothing.
11
+ ### Changed
12
+ - Format of this [CHANGELOG](http://keepachangelog.com/en/0.3.0/)
13
+ - Prefer environment variables over other options
14
+ - Use config/sequelizer.yml instead of config/database.yml
11
15
 
12
- ### Removed
13
- - Nothing.
14
-
15
- ### Fixed
16
- - Nothing.
17
-
18
- ## 0.0.6 - 2015-08-21
16
+ ## [0.0.6] - 2015-08-21
19
17
 
20
18
  ### Added
21
19
  - Support for ruby-oci8 (Oracle) in update_gemfile command
22
20
  - Read user-level configuration from ~/.config/sequelizer/database.yml
23
21
 
24
- ### Deprecated
25
- - Nothing.
26
-
27
- ### Removed
28
- - Nothing.
29
-
30
22
  ### Fixed
31
23
  - Bug where options passed as symbols where sometimes ignored.
32
24
 
33
-
34
- ## 0.0.5 - 2014-08-29
25
+ ## [0.0.5] - 2014-08-29
35
26
 
36
27
  ### Added
37
28
  - Support for TinyTDS (SQL Server) in update_gemfile command
38
29
 
39
- ### Deprecated
40
- - Nothing.
41
-
42
- ### Removed
43
- - Nothing.
44
-
45
30
  ### Fixed
46
31
  - timeout is always converted to integer before passing to Sequel.connect
47
32
 
48
-
49
- ## 0.0.4 - 2014-08-18
33
+ ## [0.0.4] - 2014-08-18
50
34
 
51
35
  ### Added
52
36
  - `init_env` command to bin/sequelizer
53
37
  - Prefer `search_path` over `schema_search_path` option
54
38
 
55
- ### Deprecated
56
- - Nothing.
57
-
58
- ### Removed
59
- - Nothing.
60
-
61
- ### Fixed
62
- - Nothing.
63
-
64
-
65
- ## 0.0.3 - 2014-07-10
39
+ ## [0.0.3] - 2014-07-10
66
40
 
67
41
  ### Added
68
42
  - Ability to view configuration by running `sequelizer config`
69
43
 
70
- ### Deprecated
71
- - Nothing.
72
-
73
- ### Removed
74
- - Nothing.
75
-
76
- ### Fixed
77
- - Nothing.
78
-
79
- ## 0.0.2 - 2014-07-10
44
+ ## [0.0.2] - 2014-07-10
80
45
 
81
46
  ### Added
82
47
  - This [CHANGELOG](http://keepachangelog.com/)
@@ -86,25 +51,10 @@ All notable changes to this project will be documented in this file.
86
51
  - Sequelizer::OptionsHash
87
52
  - Reference to issues #1, #3 in README
88
53
 
89
- ### Deprecated
90
- - Nothing.
91
-
92
- ### Removed
93
- - Nothing.
94
-
95
54
  ### Fixed
96
55
  - Prevented TestEnvConfig from polluting environment variables
97
56
 
98
- ## 0.0.1 - 2014-07-10
57
+ ## [0.0.1] - 2014-07-10
99
58
 
100
59
  ### Added
101
60
  - The project itself
102
-
103
- ### Deprecated
104
- - Nothing.
105
-
106
- ### Removed
107
- - Nothing.
108
-
109
- ### Fixed
110
- - Nothing.
@@ -11,7 +11,7 @@ module Sequelizer
11
11
  # options :: an optional set of database connection options.
12
12
  # If no options are provided, options are read from
13
13
  # config/database.yml or from .env or from environment variables.
14
- def db(options = nil)
14
+ def db(options = {})
15
15
  @_sequelizer_db ||= new_db(options)
16
16
  end
17
17
 
@@ -20,7 +20,14 @@ module Sequelizer
20
20
  # options :: an optional set of database connection options.
21
21
  # If no options are provided, options are read from
22
22
  # config/database.yml or from .env or from environment variables.
23
- def new_db(options = nil)
24
- ConnectionMaker.new(options).connection
23
+ def new_db(options = {})
24
+ cached = find_cached(options)
25
+ return cached if cached && !options[:force_new]
26
+ @cache[options] = ConnectionMaker.new(options).connection
27
+ end
28
+
29
+ def find_cached(options)
30
+ @cache ||= {}
31
+ @cache[options]
25
32
  end
26
33
  end
@@ -22,7 +22,12 @@ module Sequelizer
22
22
 
23
23
  # Returns a Sequel connection to the database
24
24
  def connection
25
- Sequel.connect(options.to_hash)
25
+ opts = options.to_hash
26
+ if url = (opts.delete(:uri) || opts.delete(:url))
27
+ Sequel.connect(url, opts)
28
+ else
29
+ Sequel.connect(options.to_hash)
30
+ end
26
31
  end
27
32
  end
28
33
  end
@@ -1,4 +1,4 @@
1
1
  module Sequelizer
2
2
  # Version for the gem
3
- VERSION = "0.0.6"
3
+ VERSION = "0.1.0"
4
4
  end
@@ -1,5 +1,6 @@
1
1
  require 'psych'
2
2
  require 'pathname'
3
+ require 'erb'
3
4
 
4
5
  module Sequelizer
5
6
  class YamlConfig
@@ -20,14 +21,14 @@ module Sequelizer
20
21
  end
21
22
 
22
23
  def initialize(config_file_path = nil)
23
- @config_file_path = Pathname.new(config_file_path || Pathname.pwd + "config" + "database.yml").expand_path
24
+ @config_file_path = Pathname.new(config_file_path || Pathname.pwd + "config" + "sequelizer.yml").expand_path
24
25
  end
25
26
 
26
27
  # Returns a set of options pulled from config/database.yml
27
28
  # or +nil+ if config/database.yml doesn't exist
28
29
  def options
29
30
  return {} unless config_file_path.exist?
30
- config['adapter'] || config[:adapter] ? config : config[environment]
31
+ config[environment] || config
31
32
  end
32
33
 
33
34
  # The environment to load from database.yml
@@ -47,7 +48,7 @@ module Sequelizer
47
48
 
48
49
  # The config as read from config/database.yml
49
50
  def config
50
- @config ||= Psych.load_file(config_file_path)
51
+ @config ||= Psych.load(ERB.new(File.read(config_file_path)).result).tap { |c| p c }
51
52
  end
52
53
  end
53
54
  end
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency 'guard-minitest', '~> 2.3'
24
24
  spec.add_development_dependency 'minitest', '~> 5.3'
25
25
  spec.add_dependency 'sequel', '~> 4.12'
26
- spec.add_dependency 'dotenv', '~> 0.11'
26
+ spec.add_dependency 'dotenv', '~> 2.1'
27
27
  spec.add_dependency 'thor', '~> 0.19'
28
28
  spec.add_dependency 'hashie', '~> 3.2'
29
29
  end
@@ -11,8 +11,8 @@ class TestYamlConfig < Minitest::Test
11
11
  mock = Minitest::Mock.new
12
12
  file_mock = Minitest::Mock.new
13
13
 
14
- stub_const(Sequelizer::YamlConfig, :Psych, mock) do
15
- mock.expect :load_file, { 'adapter' => 'sqlite' }, [file_mock]
14
+ stub_const(Sequelizer::YamlConfig, :File, mock) do
15
+ mock.expect :read, 'adapter: <%= "sqlite" %>', [file_mock]
16
16
  file_mock.expect :exist?, true
17
17
 
18
18
  @yaml_config.stub :config_file_path, file_mock do
@@ -40,7 +40,7 @@ class TestYamlConfig < Minitest::Test
40
40
  end
41
41
 
42
42
  def test_path_defaults_to_local_config
43
- assert_equal(@yaml_config.config_file_path, Pathname.pwd + "config" + "database.yml")
43
+ assert_equal(@yaml_config.config_file_path, Pathname.pwd + "config" + "sequelizer.yml")
44
44
  end
45
45
 
46
46
  def test_path_can_be_fed_pathanem_from_initialize
@@ -52,7 +52,7 @@ class TestYamlConfig < Minitest::Test
52
52
  end
53
53
 
54
54
  def test_local_is_current_directory
55
- assert_equal(Sequelizer::YamlConfig.local_config.config_file_path, Pathname.pwd + "config" + "database.yml")
55
+ assert_equal(Sequelizer::YamlConfig.local_config.config_file_path, Pathname.pwd + "config" + "sequelizer.yml")
56
56
  end
57
57
 
58
58
  def test_home_uses_home_directory
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.6
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Duryea
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-21 00:00:00.000000000 Z
11
+ date: 2016-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0.11'
89
+ version: '2.1'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0.11'
96
+ version: '2.1'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: thor
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -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.4.6
181
+ rubygems_version: 2.4.8
182
182
  signing_key:
183
183
  specification_version: 4
184
184
  summary: Sequel database connections via config/database.yml or .env
@@ -189,4 +189,3 @@ test_files:
189
189
  - test/sequelizer/test_options.rb
190
190
  - test/sequelizer/test_yaml_config.rb
191
191
  - test/test_helper.rb
192
- has_rdoc: