dry-configurable 0.9.0 → 0.11.4

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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +94 -21
  3. data/LICENSE +1 -1
  4. data/README.md +15 -27
  5. data/dry-configurable.gemspec +27 -18
  6. data/lib/dry-configurable.rb +2 -0
  7. data/lib/dry/configurable.rb +21 -146
  8. data/lib/dry/configurable/class_methods.rb +103 -0
  9. data/lib/dry/configurable/compiler.rb +45 -0
  10. data/lib/dry/configurable/config.rb +79 -135
  11. data/lib/dry/configurable/constants.rb +12 -0
  12. data/lib/dry/configurable/dsl.rb +62 -0
  13. data/lib/dry/configurable/dsl/args.rb +58 -0
  14. data/lib/dry/configurable/{error.rb → errors.rb} +5 -1
  15. data/lib/dry/configurable/instance_methods.rb +46 -0
  16. data/lib/dry/configurable/methods.rb +32 -0
  17. data/lib/dry/configurable/setting.rb +91 -17
  18. data/lib/dry/configurable/settings.rb +42 -87
  19. data/lib/dry/configurable/test_interface.rb +3 -5
  20. data/lib/dry/configurable/version.rb +3 -1
  21. metadata +30 -25
  22. data/.codeclimate.yml +0 -12
  23. data/.github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md +0 -10
  24. data/.github/ISSUE_TEMPLATE/---bug-report.md +0 -34
  25. data/.github/ISSUE_TEMPLATE/---feature-request.md +0 -18
  26. data/.github/workflows/ci.yml +0 -70
  27. data/.github/workflows/docsite.yml +0 -34
  28. data/.github/workflows/sync_configs.yml +0 -30
  29. data/.gitignore +0 -9
  30. data/.rspec +0 -4
  31. data/.rubocop.yml +0 -89
  32. data/CODE_OF_CONDUCT.md +0 -13
  33. data/CONTRIBUTING.md +0 -29
  34. data/Gemfile +0 -20
  35. data/Rakefile +0 -12
  36. data/docsite/source/index.html.md +0 -55
  37. data/docsite/source/testing.html.md +0 -27
  38. data/lib/dry/configurable/settings/argument_parser.rb +0 -50
  39. data/rakelib/rubocop.rake +0 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e2803e976eb7d92b67ba2a5fbc79b8419340b6ea1f0dd7ea752327762989507a
4
- data.tar.gz: 4da9d2ab7b1c7914bff8e7e82edc16dea3b55ea889cff85df5bb75dd8ba8e260
3
+ metadata.gz: 0ce88823de6e7eee294f11a792b0f22448792fdb5a716208aae79218877600ae
4
+ data.tar.gz: 256cb4668c2f734701f9b70869b5c3e836ca487e3b87d569e702f180b2703976
5
5
  SHA512:
6
- metadata.gz: e2d4aa78ddd0a048ab064c063ba502ab4c3e4bfc6631c2bf5d1399255bbf89916af1f8e2042dd7845d01879738589491991b2a101b6703b8ebc5626f41690a1e
7
- data.tar.gz: c9145ff55bf902b0dbb633c76c7511aa6af862fd4b31db3da5b83b5bc7990a63bc3c8afa525b43bd081cbb9c710583e111e9ef9c0c795407b10398dfa75fe2e5
6
+ metadata.gz: dd015b360b01f42e98f2df1936b5ebadbf027077fc6e7be5ff9c8aee06a1973099e67ef26488ffca0c869d45c988c5534a7d4c616d5a3ac8616fe04f337077b1
7
+ data.tar.gz: f2f69619243a1e9571060da0b568b804711ed70f100f6facf3e3eee6c7fcbcd47034ca71d25e51a47f582b0e5ed68332ad4f80d3f86fbb4442c10184d1dae351
@@ -1,44 +1,115 @@
1
- ## 0.9.0 - 2019-11-06
1
+ ## 0.11.4 2020-03-16
2
2
 
3
- ## Fixed
3
+
4
+ ### Fixed
5
+
6
+ - `Config#update` returns `self` again (issue #60 fixed via #92) (@solnic)
7
+
8
+ ### Changed
9
+
10
+ - `Setting#inspect` no longer uses its value - this could cause crashes when inspecting settings that are yet to have a value applied (e.g. when they have a constructor that expects a value to be present) (@timriley)
11
+
12
+ [Compare v0.11.3...v0.11.4](https://github.com/dry-rb/dry-configurable/compare/v0.11.3...v0.11.4)
13
+
14
+ ## 0.11.3 2020-02-22
15
+
16
+
17
+ ### Fixed
18
+
19
+ - Retrieving settings by a string name works again (issue #82) (@waiting-for-dev)
20
+
21
+
22
+ [Compare v0.11.2...v0.11.3](https://github.com/dry-rb/dry-configurable/compare/v0.11.2...v0.11.3)
23
+
24
+ ## 0.11.2 2020-02-20
25
+
26
+
27
+ ### Fixed
28
+
29
+ - Warning about redefined `Setting#value` is gone (@solnic)
30
+
31
+
32
+ [Compare v0.11.1...v0.11.2](https://github.com/dry-rb/dry-configurable/compare/v0.11.1...v0.11.2)
33
+
34
+ ## 0.11.1 2020-02-18
35
+
36
+
37
+ ### Fixed
38
+
39
+ - You can use `:settings` as a config key again (issue #80) (@solnic)
40
+ - Setting value is lazy-evaluated now, which fixes some cases where a constructor could crash with a `nil` value (@solnic)
41
+
42
+
43
+ [Compare v0.11.0...v0.11.1](https://github.com/dry-rb/dry-configurable/compare/v0.11.0...v0.11.1)
44
+
45
+ ## 0.11.0 2020-02-15
46
+
47
+ Complete rewrite of the library while keeping the public API intact. See #78 for a detailed overview.
48
+
49
+ ### Changed
50
+
51
+ - Accessing config in a parent class no longer prevents you from adding more settings in a child class (@solnic)
52
+ - (internal) New low-level Setting and Config API (@solnic)
53
+ - (internal) `config` objects use method_missing now (@solnic)
54
+
55
+ [Compare v0.10.0...v0.11.0](https://github.com/dry-rb/dry-configurable/compare/v0.10.0...v0.11.0)
56
+
57
+ ## 0.10.0 2020-01-31
58
+
59
+ YANKED because the change also broke inheritance for classes that used `configured` before other classes inherited from them.
60
+
61
+ ### Changed
62
+
63
+ - Inheriting settings no longer defines the config object. This change fixed a use case where parent class that already used its config would prevent a child class from adding new settings (@solnic)
64
+
65
+ [Compare v0.9.0...v0.10.0](https://github.com/dry-rb/dry-configurable/compare/v0.9.0...v0.10.0)
66
+
67
+ ## 0.9.0 2019-11-06
68
+
69
+
70
+ ### Fixed
4
71
 
5
72
  - Support for reserved names in settings. Some Kernel methods (`public_send` and `class` specifically) are not available if you use access settings via method call. Same for methods of the `Config` class. You can still access them with `[]` and `[]=`. Ruby keywords are fully supported. Invalid names containing special symbols (including `!` and `?`) are rejected. Note that these changes don't affect the `reader` option, if you define a setting named `:class` and pass `reader: true` ... well ... (flash-gordon)
6
73
  - Settings can be redefined in subclasses without a warning about overriding exsting methods (flash-gordon)
7
74
  - Fix warnings about using keyword arguments in 2.7 (koic)
8
75
 
9
- [Compare v0.8.3...0.9.0](https://github.com/dry-rb/dry-configurable/compare/v0.8.3...0.9.0)
10
76
 
11
- ## 0.8.3 - 2019-05-29
77
+ [Compare v0.8.3...v0.9.0](https://github.com/dry-rb/dry-configurable/compare/v0.8.3...v0.9.0)
12
78
 
13
- ## Fixed
79
+ ## 0.8.3 2019-05-29
80
+
81
+
82
+ ### Fixed
14
83
 
15
84
  - `Configurable#dup` and `Configurable#clone` make a copy of instance-level config so that it doesn't get mutated/shared across instances (flash-gordon)
16
85
 
86
+
17
87
  [Compare v0.8.2...v0.8.3](https://github.com/dry-rb/dry-configurable/compare/v0.8.2...v0.8.3)
18
88
 
19
- ## 0.8.2 - 2019-02-25
89
+ ## 0.8.2 2019-02-25
20
90
 
21
- ## Fixed
91
+
92
+ ### Fixed
22
93
 
23
94
  - Test interface support for modules ([Neznauy](https://github.com/Neznauy))
24
95
 
96
+
25
97
  [Compare v0.8.1...v0.8.2](https://github.com/dry-rb/dry-configurable/compare/v0.8.1...v0.8.2)
26
98
 
27
- ## 0.8.1 - 2019-02-06
99
+ ## 0.8.1 2019-02-06
100
+
28
101
 
29
- ## Fixed
102
+ ### Fixed
30
103
 
31
104
  - `.configure` doesn't require a block, this makes the behavior consistent with the previous versions ([flash-gordon](https://github.com/flash-gordon))
32
105
 
33
- [Compare v0.8.0...v0.8.1](https://github.com/dry-rb/dry-configurable/compare/v0.8.0...v0.8.1)
34
106
 
35
- ## 0.8.0 - 2019-02-05
107
+ [Compare v0.8.0...v0.8.1](https://github.com/dry-rb/dry-configurable/compare/v0.8.0...v0.8.1)
36
108
 
37
- ## Fixed
109
+ ## 0.8.0 2019-02-05
38
110
 
39
- - A number of bugs related to inheriting settings from parent class were fixed. Ideally, new behavior will be :100: predictable but if you observe any anomaly, please report ([flash-gordon](https://github.com/flash-gordon))
40
111
 
41
- ## Added
112
+ ### Added
42
113
 
43
114
  - Support for instance-level configuration landed. For usage, `include` the module instead of extending ([flash-gordon](https://github.com/flash-gordon))
44
115
 
@@ -57,7 +128,6 @@
57
128
  development.config.database = 'jdbc:sqlite:memory'
58
129
  development.finalize!
59
130
  ```
60
-
61
131
  - Config values can be set from a hash with `.update`. Nested settings are supported ([flash-gordon](https://github.com/flash-gordon))
62
132
 
63
133
  ```ruby
@@ -73,22 +143,25 @@
73
143
  end
74
144
  ```
75
145
 
76
- ## Changed
146
+ ### Fixed
147
+
148
+ - A number of bugs related to inheriting settings from parent class were fixed. Ideally, new behavior will be :100: predictable but if you observe any anomaly, please report ([flash-gordon](https://github.com/flash-gordon))
149
+
150
+ ### Changed
77
151
 
78
152
  - [BREAKING] Minimal supported Ruby version is set to 2.3 ([flash-gordon](https://github.com/flash-gordon))
79
153
 
80
154
  [Compare v0.7.0...v0.8.0](https://github.com/dry-rb/dry-configurable/compare/v0.7.0...v0.8.0)
81
155
 
82
- ## 0.7.0 - 2017-04-25
156
+ ## 0.7.0 2017-04-25
157
+
83
158
 
84
- ## Added
159
+ ### Added
85
160
 
86
161
  - Introduce `Configurable.finalize!` which freezes config and its dependencies ([qcam](https://github.com/qcam))
87
162
 
88
- ## Fixed
163
+ ### Fixed
89
164
 
90
165
  - Allow for boolean false as default setting value ([yuszuv](https://github.com/yuszuv))
91
166
  - Convert nested configs to nested hashes with `Config#to_h` ([saverio-kantox](https://github.com/saverio-kantox))
92
167
  - Disallow modification on frozen config ([qcam](https://github.com/qcam))
93
-
94
- [Compare v0.6.2...v0.7.0](https://github.com/dry-rb/dry-configurable/compare/v0.6.2...v0.7.0)
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2019 dry-rb team
3
+ Copyright (c) 2015-2020 dry-rb team
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
data/README.md CHANGED
@@ -1,40 +1,28 @@
1
- [gitter]: https://gitter.im/dry-rb/chat
2
1
  [gem]: https://rubygems.org/gems/dry-configurable
3
- [travis]: https://travis-ci.org/dry-rb/dry-configurable
4
- [inch]: http://inch-ci.org/github/dry-rb/dry-configurable
2
+ [actions]: https://github.com/dry-rb/dry-configurable/actions
3
+ [codacy]: https://www.codacy.com/gh/dry-rb/dry-configurable
5
4
  [chat]: https://dry-rb.zulipchat.com
5
+ [inchpages]: http://inch-ci.org/github/dry-rb/dry-configurable
6
6
 
7
7
  # dry-configurable [![Join the chat at https://dry-rb.zulipchat.com](https://img.shields.io/badge/dry--rb-join%20chat-%23346b7a.svg)][chat]
8
8
 
9
- [![Gem Version](https://img.shields.io/gem/v/dry-configurable.svg)][gem]
10
- [![Build Status](https://img.shields.io/travis/dry-rb/dry-configurable.svg)][travis]
11
- [![Maintainability](https://api.codeclimate.com/v1/badges/25311e81391498d6b7c8/maintainability)](https://codeclimate.com/github/dry-rb/dry-configurable/maintainability)
12
- [![Test Coverage](https://api.codeclimate.com/v1/badges/25311e81391498d6b7c8/test_coverage)](https://codeclimate.com/github/dry-rb/dry-configurable/test_coverage)
13
- [![API Documentation Coverage](http://inch-ci.org/github/dry-rb/dry-configurable.svg)][inch]
9
+ [![Gem Version](https://badge.fury.io/rb/dry-configurable.svg)][gem]
10
+ [![CI Status](https://github.com/dry-rb/dry-configurable/workflows/ci/badge.svg)][actions]
11
+ [![Codacy Badge](https://api.codacy.com/project/badge/Grade/0276a97990e04eb0ac722b3e7f3620b5)][codacy]
12
+ [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/0276a97990e04eb0ac722b3e7f3620b5)][codacy]
13
+ [![Inline docs](http://inch-ci.org/github/dry-rb/dry-configurable.svg?branch=master)][inchpages]
14
14
 
15
- ## Installation
16
-
17
- Add this line to your application's Gemfile:
18
-
19
- ```ruby
20
- gem 'dry-configurable'
21
- ```
22
-
23
- And then execute:
24
-
25
- ```sh
26
- $ bundle
27
- ```
15
+ ## Links
28
16
 
29
- Or install it yourself as:
17
+ * [User documentation](http://dry-rb.org/gems/dry-configurable)
18
+ * [API documentation](http://rubydoc.info/gems/dry-configurable)
30
19
 
31
- ```sh
32
- $ gem install dry-configurable
33
- ```
20
+ ## Supported Ruby versions
34
21
 
35
- ## Links
22
+ This library officially supports the following Ruby versions:
36
23
 
37
- * [Documentation](http://dry-rb.org/gems/dry-configurable)
24
+ * MRI >= `2.4`
25
+ * jruby >= `9.2`
38
26
 
39
27
  ## License
40
28
 
@@ -1,29 +1,38 @@
1
- require File.expand_path('../lib/dry/configurable/version', __FILE__)
1
+ # frozen_string_literal: true
2
+ # this file is managed by dry-rb/devtools project
3
+
4
+ lib = File.expand_path('lib', __dir__)
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+ require 'dry/configurable/version'
2
7
 
3
8
  Gem::Specification.new do |spec|
4
9
  spec.name = 'dry-configurable'
5
- spec.version = Dry::Configurable::VERSION
6
- spec.authors = ['Andy Holland']
7
- spec.email = ['andyholland1991@aol.com']
8
- spec.summary = 'A mixin to add configuration functionality to your classes'
9
- spec.homepage = 'https://github.com/dry-rb/dry-configurable'
10
+ spec.authors = ["Andy Holland"]
11
+ spec.email = ["andyholland1991@aol.com"]
10
12
  spec.license = 'MIT'
13
+ spec.version = Dry::Configurable::VERSION.dup
11
14
 
12
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec|bin)/}) }
13
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
14
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.summary = "A mixin to add configuration functionality to your classes"
16
+ spec.description = spec.summary
17
+ spec.homepage = 'https://dry-rb.org/gems/dry-configurable'
18
+ spec.files = Dir["CHANGELOG.md", "LICENSE", "README.md", "dry-configurable.gemspec", "lib/**/*"]
19
+ spec.bindir = 'bin'
20
+ spec.executables = []
15
21
  spec.require_paths = ['lib']
16
22
 
17
- spec.metadata = {
18
- 'source_code_uri' => 'https://github.com/dry-rb/dry-configurable',
19
- 'changelog_uri' => 'https://github.com/dry-rb/dry-configurable/blob/master/CHANGELOG.md'
20
- }
23
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
24
+ spec.metadata['changelog_uri'] = 'https://github.com/dry-rb/dry-configurable/blob/master/CHANGELOG.md'
25
+ spec.metadata['source_code_uri'] = 'https://github.com/dry-rb/dry-configurable'
26
+ spec.metadata['bug_tracker_uri'] = 'https://github.com/dry-rb/dry-configurable/issues'
21
27
 
22
28
  spec.required_ruby_version = ">= 2.4.0"
23
- spec.add_runtime_dependency 'concurrent-ruby', '~> 1.0'
24
- spec.add_runtime_dependency 'dry-core', '~> 0.4', '>= 0.4.7'
25
29
 
26
- spec.add_development_dependency 'bundler'
27
- spec.add_development_dependency 'rake'
28
- spec.add_development_dependency 'rspec'
30
+ # to update dependencies edit project.yml
31
+ spec.add_runtime_dependency "concurrent-ruby", "~> 1.0"
32
+ spec.add_runtime_dependency "dry-core", "~> 0.4", ">= 0.4.7"
33
+ spec.add_runtime_dependency "dry-equalizer", "~> 0.2"
34
+
35
+ spec.add_development_dependency "bundler"
36
+ spec.add_development_dependency "rake"
37
+ spec.add_development_dependency "rspec"
29
38
  end
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/configurable'
@@ -1,10 +1,13 @@
1
- require 'dry/core/constants'
2
- require 'dry/configurable/settings'
3
- require 'dry/configurable/error'
4
- require 'dry/configurable/version'
1
+ # frozen_string_literal: true
2
+
3
+ require 'concurrent/array'
4
+
5
+ require 'dry/configurable/constants'
6
+ require 'dry/configurable/class_methods'
7
+ require 'dry/configurable/instance_methods'
8
+ require 'dry/configurable/config'
9
+ require 'dry/configurable/setting'
5
10
 
6
- # A collection of micro-libraries, each intended to encapsulate
7
- # a common task in Ruby
8
11
  module Dry
9
12
  # A simple configuration mixin
10
13
  #
@@ -40,150 +43,22 @@ module Dry
40
43
  #
41
44
  # @api public
42
45
  module Configurable
43
- include Dry::Core::Constants
44
-
45
- module ClassMethods
46
- # @private
47
- def self.extended(base)
48
- base.instance_exec do
49
- @settings = Settings.new
50
- end
51
- end
52
-
53
- # Add a setting to the configuration
54
- #
55
- # @param [Mixed] key
56
- # The accessor key for the configuration value
57
- # @param [Mixed] default
58
- # The default config value
59
- #
60
- # @yield
61
- # If a block is given, it will be evaluated in the context of
62
- # a new configuration class, and bound as the default value
63
- #
64
- # @return [Dry::Configurable::Config]
65
- #
66
- # @api public
67
- def setting(key, value = Undefined, options = Undefined, &block)
68
- raise_already_defined_config(key) if _settings.config_defined?
69
-
70
- setting = _settings.add(key, value, options, &block)
71
-
72
- if setting.reader?
73
- readers = singleton_class < Configurable ? singleton_class : self
74
- readers.send(:define_method, setting.name) { config[setting.name] }
75
- end
76
- end
77
-
78
- # Return an array of setting names
79
- #
80
- # @return [Set]
81
- #
82
- # @api public
83
- def settings
84
- _settings.names
85
- end
86
-
87
- # @private no, really...
88
- def _settings
89
- @settings
90
- end
91
-
92
- private
93
-
94
- # @private
95
- def raise_already_defined_config(key)
96
- raise AlreadyDefinedConfig,
97
- "Cannot add setting +#{key}+, #{self} is already configured"
98
- end
99
-
100
- # @private
101
- def inherited(subclass)
102
- parent = self
103
- subclass.instance_exec do
104
- @settings = parent._settings.dup
105
- end
106
-
107
- if singleton_class < Configurable
108
- parent_config = @config
109
- subclass.instance_exec do
110
- @config = _settings.create_config
111
- @config.define!(parent_config.to_h) if parent_config.defined?
112
- end
113
- end
114
-
115
- super
116
- end
117
- end
118
-
119
- class << self
120
- # @private
121
- def extended(base)
122
- base.extend(ClassMethods)
123
- base.class_eval do
124
- @config = _settings.create_config
125
- end
126
- end
127
-
128
- # @private
129
- def included(base)
130
- base.extend(ClassMethods)
131
- end
132
- end
133
-
134
- # @private
135
- def initialize(*)
136
- @config = self.class._settings.create_config
46
+ # @api private
47
+ def self.extended(klass)
137
48
  super
49
+ klass.extend(ClassMethods)
138
50
  end
139
51
 
140
- # Return configuration
141
- #
142
- # @return [Dry::Configurable::Config]
143
- #
144
- # @api public
145
- def config
146
- return @config if @config.defined?
147
- @config.define!
148
- end
149
-
150
- # Return configuration
151
- #
152
- # @yield [Dry::Configuration::Config]
153
- #
154
- # @return [Dry::Configurable::Config]
155
- #
156
- # @api public
157
- def configure
158
- raise FrozenConfig, 'Cannot modify frozen config' if frozen?
159
- yield(config) if block_given?
160
- self
161
- end
162
-
163
- # Finalize and freeze configuration
164
- #
165
- # @return [Dry::Configurable::Config]
166
- #
167
- # @api public
168
- def finalize!
169
- freeze
170
- config.finalize!
171
- end
172
-
173
- # @api public
174
- def dup
175
- super.tap do |copy|
176
- copy.instance_variable_set(:@config, config.dup)
177
- end
178
- end
52
+ # @api private
53
+ def self.included(klass)
54
+ super
55
+ klass.class_eval do
56
+ extend(ClassMethods)
57
+ include(InstanceMethods)
179
58
 
180
- # @api public
181
- def clone
182
- if frozen?
183
- super
184
- else
185
- super.tap do |copy|
186
- copy.instance_variable_set(:@config, config.dup)
59
+ class << self
60
+ undef :config
61
+ undef :configure
187
62
  end
188
63
  end
189
64
  end