dry-configurable 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bbbc7ef5946aeb5c65bbb665c46f83889bb96bd3
4
- data.tar.gz: c07ffda1dbf3139f8ee01c5fdf1c58256f7dfa69
3
+ metadata.gz: 3ad76ba634372fef286ee4ed41858c38db434eb2
4
+ data.tar.gz: 0137864a8d45cb1c0e1b0b583263d12fe2a4aeea
5
5
  SHA512:
6
- metadata.gz: 978be50370afebe7518aad050bac45771d2fc7d48b45159537d4f6d8998deb3297ce26f0c6eb04214cf6f3dfc039f599b69b521c0aa6bfed993ea59bc301f634
7
- data.tar.gz: d532e06d2d8236f3c1bad62d416300621a9bb30ec769743987faeaf67fcab743bd04593dccf466dbfeff801ca99c47877f8f591904c8babd066d9ee92c15250a
6
+ metadata.gz: 439db458f72ce8c7a1ed41565916078d8fc2659002daf2218492297b2f5d25d41b6de52aa1538c27acb6203b464d5ce2391793ab0de4fdaefac1d64234c5f6a8
7
+ data.tar.gz: 869183f4d81a902494e20d183fa116c2afd5aa54c526c6fcdd2b0a52c717e493c62fbc47228f14de3066413d5e1b2075ef8503633248fdccbb9818c8592cb314
data/README.md CHANGED
@@ -2,7 +2,10 @@
2
2
 
3
3
  <a href="https://rubygems.org/gems/dry-configurable" target="_blank">![Gem Version](https://badge.fury.io/rb/dry-configurable.svg)</a>
4
4
  <a href="https://travis-ci.org/dryrb/dry-configurable" target="_blank">![Build Status](https://travis-ci.org/dryrb/dry-configurable.svg?branch=master)</a>
5
- <a href="http://inch-ci.org/github/dryrb/dry-configurable" target="_blank">![Inline docs](http://inch-ci.org/github/dryrb/dry-configurable.svg?branch=master&style=flat)</a>
5
+ <a href="https://gemnasium.com/dryrb/dry-configurable" target="_blank">![Dependency Status](https://gemnasium.com/dryrb/dry-configurable.svg)</a>
6
+ <a href="https://codeclimate.com/github/dryrb/dry-configurable" target="_blank">![Code Climate](https://codeclimate.com/github/dryrb/dry-configurable/badges/gpa.svg)</a>
7
+ <a href="http://inch-ci.org/github/dryrb/dry-configurable" target="_blank">![Documentation Status](http://inch-ci.org/github/dryrb/dry-configurable.svg?branch=master&style=flat)</a>
8
+
6
9
 
7
10
  ## Synopsis
8
11
 
@@ -2,6 +2,8 @@ require 'thread_safe'
2
2
  require 'dry/configurable/config'
3
3
  require 'dry/configurable/version'
4
4
 
5
+ # A collection of micro-libraries, each intended to encapsulate
6
+ # a common task in Ruby
5
7
  module Dry
6
8
  # A simple configuration mixin
7
9
  #
@@ -15,7 +17,7 @@ module Dry
15
17
  # end
16
18
  # end
17
19
  #
18
- # App.confiure do |config|
20
+ # App.configure do |config|
19
21
  # config.database.dsn = 'jdbc:sqlite:memory'
20
22
  # end
21
23
  #
@@ -33,6 +35,14 @@ module Dry
33
35
  @_settings = ThreadSafe::Cache.new
34
36
  end
35
37
  end
38
+
39
+ # @private
40
+ def inherited(subclass)
41
+ subclass.instance_variable_set(:@_config_mutex, @_config_mutex)
42
+ subclass.instance_variable_set(:@_settings, @_settings)
43
+ super
44
+ end
45
+
36
46
  # Return configuration
37
47
  #
38
48
  # @return [Dry::Configurable::Config]
@@ -44,6 +54,7 @@ module Dry
44
54
  @_config = Config.new(*_settings.keys).new(*_settings.values) unless _settings.empty?
45
55
  end
46
56
  end
57
+
47
58
  # Return configuration
48
59
  #
49
60
  # @yield [Dry::Configuration::Config]
@@ -54,6 +65,7 @@ module Dry
54
65
  def configure
55
66
  yield(config) if block_given?
56
67
  end
68
+
57
69
  # Add a setting to the configuration
58
70
  #
59
71
  # @param [Mixed] key
@@ -1,6 +1,6 @@
1
1
  module Dry
2
2
  module Configurable
3
3
  # @api public
4
- VERSION = '0.1.1'.freeze
4
+ VERSION = '0.1.2'.freeze
5
5
  end
6
6
  end
@@ -1,91 +1,25 @@
1
1
  RSpec.describe Dry::Configurable do
2
- describe 'settings' do
3
- context 'without default value' do
4
- let(:configuration) do
5
- Class.new do
6
- extend Dry::Configurable
7
-
8
- setting :dsn
9
- end
10
- end
11
-
12
- it 'returns nil' do
13
- expect(configuration.config.dsn).to be(nil)
2
+ context 'when extended' do
3
+ let(:klass) do
4
+ Class.new do
5
+ extend Dry::Configurable
14
6
  end
15
7
  end
16
8
 
17
- context 'with default value' do
18
- let(:configuration) do
19
- Class.new do
20
- extend Dry::Configurable
21
-
22
- setting :dsn, 'sqlite:memory'
23
- end
24
- end
25
-
26
- it 'returns the default value' do
27
- expect(configuration.config.dsn).to eq('sqlite:memory')
28
- end
29
- end
30
-
31
- context 'nested configuration' do
32
- let(:configuration) do
33
- Class.new do
34
- extend Dry::Configurable
35
-
36
- setting :database do
37
- setting :dsn, 'sqlite:memory'
38
- end
39
- end
40
- end
41
-
42
- it 'returns the default value' do
43
- expect(configuration.config.database.dsn).to eq('sqlite:memory')
44
- end
45
- end
9
+ it_behaves_like 'a configurable class'
46
10
  end
47
11
 
48
- describe 'configuration' do
49
- context 'without nesting' do
50
- let(:configuration) do
51
- Class.new do
52
- extend Dry::Configurable
53
-
54
- setting :dsn, 'sqlite:memory'
55
- end
56
- end
57
-
58
- before do
59
- configuration.configure do |config|
60
- config.dsn = 'jdbc:sqlite:memory'
61
- end
62
- end
63
-
64
- it 'updates the config value' do
65
- expect(configuration.config.dsn).to eq('jdbc:sqlite:memory')
12
+ context 'when extended then inherited' do
13
+ let(:base_klass) do
14
+ Class.new do
15
+ extend Dry::Configurable
66
16
  end
67
17
  end
68
18
 
69
- context 'with nesting' do
70
- let(:configuration) do
71
- Class.new do
72
- extend Dry::Configurable
73
-
74
- setting :database do
75
- setting :dsn, 'sqlite:memory'
76
- end
77
- end
78
- end
79
-
80
- before do
81
- configuration.configure do |config|
82
- config.database.dsn = 'jdbc:sqlite:memory'
83
- end
84
- end
85
-
86
- it 'updates the config value' do
87
- expect(configuration.config.database.dsn).to eq('jdbc:sqlite:memory')
88
- end
19
+ let(:klass) do
20
+ Class.new(base_klass)
89
21
  end
22
+
23
+ it_behaves_like 'a configurable class'
90
24
  end
91
25
  end
@@ -1,3 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require 'dry/configurable'
4
+
5
+ Dir[Pathname(__FILE__).dirname.join('support/**/*.rb').to_s].each do |file|
6
+ require file
7
+ end
@@ -0,0 +1,73 @@
1
+ RSpec.shared_examples 'a configurable class' do
2
+ describe Dry::Configurable do
3
+ describe 'settings' do
4
+ context 'without default value' do
5
+ before do
6
+ klass.setting :dsn
7
+ end
8
+
9
+ it 'returns nil' do
10
+ expect(klass.config.dsn).to be(nil)
11
+ end
12
+ end
13
+
14
+ context 'with default value' do
15
+ before do
16
+ klass.setting :dsn, 'sqlite:memory'
17
+ end
18
+
19
+ it 'returns the default value' do
20
+ expect(klass.config.dsn).to eq('sqlite:memory')
21
+ end
22
+ end
23
+
24
+ context 'nested configuration' do
25
+ before do
26
+ klass.setting :database do
27
+ setting :dsn, 'sqlite:memory'
28
+ end
29
+ end
30
+
31
+ it 'returns the default value' do
32
+ expect(klass.config.database.dsn).to eq('sqlite:memory')
33
+ end
34
+ end
35
+ end
36
+
37
+ describe 'configuration' do
38
+ context 'without nesting' do
39
+ before do
40
+ klass.setting :dsn, 'sqlite:memory'
41
+ end
42
+
43
+ before do
44
+ klass.configure do |config|
45
+ config.dsn = 'jdbc:sqlite:memory'
46
+ end
47
+ end
48
+
49
+ it 'updates the config value' do
50
+ expect(klass.config.dsn).to eq('jdbc:sqlite:memory')
51
+ end
52
+ end
53
+
54
+ context 'with nesting' do
55
+ before do
56
+ klass.setting :database do
57
+ setting :dsn, 'sqlite:memory'
58
+ end
59
+ end
60
+
61
+ before do
62
+ klass.configure do |config|
63
+ config.database.dsn = 'jdbc:sqlite:memory'
64
+ end
65
+ end
66
+
67
+ it 'updates the config value' do
68
+ expect(klass.config.database.dsn).to eq('jdbc:sqlite:memory')
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-configurable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Holland
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-20 00:00:00.000000000 Z
11
+ date: 2015-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thread_safe
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  description:
@@ -73,11 +73,11 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
- - .gitignore
77
- - .rspec
78
- - .rubocop.yml
79
- - .rubocop_todo.yml
80
- - .travis.yml
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".rubocop.yml"
79
+ - ".rubocop_todo.yml"
80
+ - ".travis.yml"
81
81
  - Gemfile
82
82
  - LICENSE
83
83
  - README.md
@@ -90,6 +90,7 @@ files:
90
90
  - rakelib/rubocop.rake
91
91
  - spec/integration/configurable_spec.rb
92
92
  - spec/spec_helper.rb
93
+ - spec/support/shared_examples/configurable.rb
93
94
  homepage: https://github.com/dryrb/dry-configurable
94
95
  licenses:
95
96
  - MIT
@@ -100,20 +101,21 @@ require_paths:
100
101
  - lib
101
102
  required_ruby_version: !ruby/object:Gem::Requirement
102
103
  requirements:
103
- - - '>='
104
+ - - ">="
104
105
  - !ruby/object:Gem::Version
105
106
  version: '0'
106
107
  required_rubygems_version: !ruby/object:Gem::Requirement
107
108
  requirements:
108
- - - '>='
109
+ - - ">="
109
110
  - !ruby/object:Gem::Version
110
111
  version: '0'
111
112
  requirements: []
112
113
  rubyforge_project:
113
- rubygems_version: 2.4.6
114
+ rubygems_version: 2.4.5.1
114
115
  signing_key:
115
116
  specification_version: 4
116
117
  summary: A mixin to add configuration functionality to your classes
117
118
  test_files:
118
119
  - spec/integration/configurable_spec.rb
119
120
  - spec/spec_helper.rb
121
+ - spec/support/shared_examples/configurable.rb