dry-core 0.4.5 → 0.4.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +147 -40
- data/LICENSE +20 -0
- data/README.md +18 -36
- data/dry-core.gemspec +25 -23
- data/lib/dry-core.rb +2 -0
- data/lib/dry/core.rb +2 -0
- data/lib/dry/core/cache.rb +2 -0
- data/lib/dry/core/class_attributes.rb +30 -8
- data/lib/dry/core/class_builder.rb +8 -3
- data/lib/dry/core/constants.rb +48 -8
- data/lib/dry/core/deprecations.rb +11 -9
- data/lib/dry/core/descendants_tracker.rb +2 -0
- data/lib/dry/core/errors.rb +2 -0
- data/lib/dry/core/extensions.rb +2 -0
- data/lib/dry/core/inflector.rb +5 -2
- data/lib/dry/core/memoizable.rb +2 -0
- data/lib/dry/core/version.rb +3 -1
- metadata +24 -30
- data/.gitignore +0 -10
- data/.inch.yml +0 -4
- data/.rspec +0 -3
- data/.rubocop.yml +0 -31
- data/.travis.yml +0 -31
- data/CONTRIBUTING.md +0 -29
- data/Gemfile +0 -22
- data/LICENSE.txt +0 -21
- data/Rakefile +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 538785d6f230fed2829eb31c2eed7b4f878db06f3d69703329e571327abea700
|
4
|
+
data.tar.gz: 6df94708151283cf120d590581171931141f999d8bdace6a825d80f61ac220e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ab27069408443161d3bed839e061e35ff0c683d3d9023d6834b1d45e48d44eb13eba350b3c7760312ace4eac3d83b8c008eada7878338fa017c96b195c02acc
|
7
|
+
data.tar.gz: 73c828d5271872b6b5a2b0cbf1d53075b3845ad36e82a90c7d12e35f7154a807c1320de5233eb9c26eeba35cf4078ed0b3fa5deb2b9bc7306adb26c10174d13a
|
data/CHANGELOG.md
CHANGED
@@ -1,137 +1,244 @@
|
|
1
|
-
|
1
|
+
## 0.4.10 2020-11-19
|
2
|
+
|
2
3
|
|
3
4
|
### Added
|
4
5
|
|
5
|
-
|
6
|
+
- `ClassAttributes.defines` gets a new option for coercing values (tallica)
|
7
|
+
```ruby
|
8
|
+
class Builder
|
9
|
+
extend Dry::Core::ClassAttributes
|
10
|
+
|
11
|
+
defines :nodes, coerce: -> value { Integer(value) }
|
12
|
+
end
|
13
|
+
```
|
14
|
+
`:coerce` works with any callable as well as types from dry-types
|
15
|
+
```ruby
|
16
|
+
defines :nodes, coerce: Dry::Types['coercible.integer']
|
17
|
+
```
|
18
|
+
- `Constants::IDENTITY` which is the identity function (flash-gordon)
|
19
|
+
|
6
20
|
|
7
|
-
[Compare v0.4.
|
21
|
+
[Compare v0.4.9...v0.4.10](https://github.com/dry-rb/dry-core/compare/v0.4.9...v0.4.10)
|
22
|
+
|
23
|
+
## 0.4.9 2019-08-09
|
8
24
|
|
9
|
-
# v0.4.4 2018-02-10
|
10
25
|
|
11
26
|
### Added
|
12
27
|
|
13
|
-
|
14
|
-
|
28
|
+
- `Undefined.coalesce` takes a variable number of arguments and returns the first non-`Undefined` value (flash-gordon)
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
Undefined.coalesce(Undefined, Undefined, :foo) # => :foo
|
32
|
+
```
|
33
|
+
|
34
|
+
### Fixed
|
35
|
+
|
36
|
+
- `Undefined.{dup,clone}` returns `Undefined` back, `Undefined` is a singleton (flash-gordon)
|
37
|
+
|
38
|
+
|
39
|
+
[Compare v0.4.8...v0.4.9](https://github.com/dry-rb/dry-core/compare/v0.4.8...v0.4.9)
|
40
|
+
|
41
|
+
## 0.4.8 2019-06-23
|
42
|
+
|
43
|
+
|
44
|
+
### Added
|
45
|
+
|
46
|
+
- `Undefined.map` for mapping non-undefined values (flash-gordon)
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
something = 1
|
50
|
+
Undefined.map(something) { |v| v + 1 } # => 2
|
51
|
+
|
52
|
+
something = Undefined
|
53
|
+
Undefined.map(something) { |v| v + 1 } # => Undefined
|
54
|
+
```
|
55
|
+
|
56
|
+
|
57
|
+
[Compare v0.4.7...v0.4.8](https://github.com/dry-rb/dry-core/compare/v0.4.7...v0.4.8)
|
58
|
+
|
59
|
+
## 0.4.7 2018-06-25
|
60
|
+
|
61
|
+
|
62
|
+
### Fixed
|
63
|
+
|
64
|
+
- Fix default logger for deprecations, it now uses `$stderr` by default, as it should (flash-gordon)
|
65
|
+
|
66
|
+
|
67
|
+
[Compare v0.4.6...v0.4.7](https://github.com/dry-rb/dry-core/compare/v0.4.6...v0.4.7)
|
68
|
+
|
69
|
+
## 0.4.6 2018-05-15
|
70
|
+
|
71
|
+
|
72
|
+
### Changed
|
73
|
+
|
74
|
+
- Trigger constant autoloading in the class builder (radar)
|
75
|
+
|
76
|
+
[Compare v0.4.5...v0.4.6](https://github.com/dry-rb/dry-core/compare/v0.4.5...v0.4.6)
|
77
|
+
|
78
|
+
## 0.4.5 2018-03-14
|
79
|
+
|
80
|
+
|
81
|
+
### Added
|
82
|
+
|
83
|
+
- `Dry::Core::Memoizable`, which provides a `memoize` macro for memoizing results of instance methods (timriley)
|
84
|
+
|
85
|
+
|
86
|
+
[Compare v0.4.4...v0.4.5](https://github.com/dry-rb/dry-core/compare/v0.4.4...v0.4.5)
|
87
|
+
|
88
|
+
## 0.4.4 2018-02-10
|
89
|
+
|
90
|
+
|
91
|
+
### Added
|
92
|
+
|
93
|
+
- `deprecate_constant` overrides `Module#deprecate_constant` and issues a labeled message on accessing a deprecated constant (flash-gordon)
|
94
|
+
- `Undefined.default` which accepts two arguments and returns the first if it's not `Undefined`; otherwise, returns the second one or yields a block (flash-gordon)
|
95
|
+
|
15
96
|
|
16
97
|
[Compare v0.4.3...v0.4.4](https://github.com/dry-rb/dry-core/compare/v0.4.3...v0.4.4)
|
17
98
|
|
18
|
-
|
99
|
+
## 0.4.3 2018-02-03
|
100
|
+
|
19
101
|
|
20
102
|
### Added
|
21
103
|
|
22
|
-
|
104
|
+
- `Dry::Core::DescendantsTracker` which is a maintained version of the [`descendants_tracker`](https://github.com/dkubb/descendants_tracker) gem (flash-gordon)
|
105
|
+
|
23
106
|
|
24
|
-
[Compare v0.4.2...v0.4.3](https://github.com/dry-rb/dry-core/compare/v0.4.2...
|
107
|
+
[Compare v0.4.2...v0.4.3](https://github.com/dry-rb/dry-core/compare/v0.4.2...v0.4.3)
|
108
|
+
|
109
|
+
## 0.4.2 2017-12-16
|
25
110
|
|
26
|
-
# v0.4.2 2017-12-16
|
27
111
|
|
28
112
|
### Fixed
|
29
113
|
|
30
|
-
|
114
|
+
- Class attributes now support private setters/getters (flash-gordon)
|
115
|
+
|
31
116
|
|
32
117
|
[Compare v0.4.1...v0.4.2](https://github.com/dry-rb/dry-core/compare/v0.4.1...v0.4.2)
|
33
118
|
|
34
|
-
|
119
|
+
## 0.4.1 2017-11-04
|
120
|
+
|
35
121
|
|
36
122
|
### Changed
|
37
123
|
|
38
|
-
|
124
|
+
- Improved error message on invalid attribute value (GustavoCaso)
|
39
125
|
|
40
126
|
[Compare v0.4.0...v0.4.1](https://github.com/dry-rb/dry-core/compare/v0.4.0...v0.4.1)
|
41
127
|
|
42
|
-
|
128
|
+
## 0.4.0 2017-11-02
|
129
|
+
|
43
130
|
|
44
131
|
### Added
|
45
132
|
|
46
|
-
|
133
|
+
- Added the `:type` option to class attributes, you can now restrict attribute values with a type. You can either use plain ruby types (`Integer`, `String`, etc) or `dry-types` (GustavoCaso)
|
47
134
|
|
48
135
|
```ruby
|
49
|
-
|
50
|
-
|
136
|
+
class Foo
|
137
|
+
extend Dry::Core::ClassAttributes
|
51
138
|
|
52
|
-
|
53
|
-
|
54
|
-
|
139
|
+
defines :ruby_attr, type: Integer
|
140
|
+
defines :dry_attr, type: Dry::Types['strict.int']
|
141
|
+
end
|
55
142
|
```
|
56
143
|
|
144
|
+
|
57
145
|
[Compare v0.3.4...v0.4.0](https://github.com/dry-rb/dry-core/compare/v0.3.4...v0.4.0)
|
58
146
|
|
59
|
-
|
147
|
+
## 0.3.4 2017-09-29
|
148
|
+
|
60
149
|
|
61
150
|
### Fixed
|
62
151
|
|
63
|
-
|
152
|
+
- `Deprecations` output is set to `$stderr` by default now (solnic)
|
153
|
+
|
64
154
|
|
65
155
|
[Compare v0.3.3...v0.3.4](https://github.com/dry-rb/dry-core/compare/v0.3.3...v0.3.4)
|
66
156
|
|
67
|
-
|
157
|
+
## 0.3.3 2017-08-31
|
158
|
+
|
68
159
|
|
69
160
|
### Fixed
|
70
161
|
|
71
|
-
|
162
|
+
- The Deprecations module now shows the right caller line (flash-gordon)
|
163
|
+
|
72
164
|
|
73
165
|
[Compare v0.3.2...v0.3.3](https://github.com/dry-rb/dry-core/compare/v0.3.2...v0.3.3)
|
74
166
|
|
75
|
-
|
167
|
+
## 0.3.2 2017-08-31
|
168
|
+
|
76
169
|
|
77
170
|
### Added
|
78
171
|
|
79
|
-
|
172
|
+
- Accept an existing logger object in `Dry::Core::Deprecations.set_logger!` (flash-gordon)
|
173
|
+
|
80
174
|
|
81
175
|
[Compare v0.3.1...v0.3.2](https://github.com/dry-rb/dry-core/compare/v0.3.1...v0.3.2)
|
82
176
|
|
83
|
-
|
177
|
+
## 0.3.1 2017-05-27
|
178
|
+
|
84
179
|
|
85
180
|
### Added
|
86
181
|
|
87
|
-
|
182
|
+
- Support for building classes within an existing namespace (flash-gordon)
|
183
|
+
|
88
184
|
|
89
185
|
[Compare v0.3.0...v0.3.1](https://github.com/dry-rb/dry-core/compare/v0.3.0...v0.3.1)
|
90
186
|
|
91
|
-
|
187
|
+
## 0.3.0 2017-05-05
|
188
|
+
|
92
189
|
|
93
190
|
### Changed
|
94
191
|
|
95
|
-
|
192
|
+
- Class attributes are initialized _before_ running the `inherited` hook. It's slightly more convenient behavior and it's very unlikely anyone will be affected by this, but technically this is a breaking change (flash-gordon)
|
96
193
|
|
97
194
|
[Compare v0.2.4...v0.3.0](https://github.com/dry-rb/dry-core/compare/v0.2.4...v0.3.0)
|
98
195
|
|
99
|
-
|
196
|
+
## 0.2.4 2017-01-26
|
197
|
+
|
100
198
|
|
101
199
|
### Fixed
|
102
200
|
|
103
|
-
|
201
|
+
- Do not require deprecated method to be defined (flash-gordon)
|
202
|
+
|
104
203
|
|
105
204
|
[Compare v0.2.3...v0.2.4](https://github.com/dry-rb/dry-core/compare/v0.2.3...v0.2.4)
|
106
205
|
|
107
|
-
|
206
|
+
## 0.2.3 2016-12-30
|
207
|
+
|
108
208
|
|
109
209
|
### Fixed
|
110
210
|
|
111
|
-
|
211
|
+
- Fix warnings on using uninitialized class attributes (flash-gordon)
|
212
|
+
|
112
213
|
|
113
214
|
[Compare v0.2.2...v0.2.3](https://github.com/dry-rb/dry-core/compare/v0.2.2...v0.2.3)
|
114
215
|
|
115
|
-
|
216
|
+
## 0.2.2 2016-12-30
|
217
|
+
|
116
218
|
|
117
219
|
### Added
|
118
220
|
|
119
|
-
|
221
|
+
- `ClassAttributes` which provides `defines` method for defining get-or-set methods (flash-gordon)
|
222
|
+
|
120
223
|
|
121
224
|
[Compare v0.2.1...v0.2.2](https://github.com/dry-rb/dry-core/compare/v0.2.1...v0.2.2)
|
122
225
|
|
123
|
-
|
226
|
+
## 0.2.1 2016-11-18
|
227
|
+
|
124
228
|
|
125
229
|
### Added
|
126
230
|
|
127
|
-
|
231
|
+
- `Constants` are now available in nested scopes (flash-gordon)
|
232
|
+
|
128
233
|
|
129
234
|
[Compare v0.2.0...v0.2.1](https://github.com/dry-rb/dry-core/compare/v0.2.0...v0.2.1)
|
130
235
|
|
131
|
-
|
236
|
+
## 0.2.0 2016-11-01
|
237
|
+
|
238
|
+
|
132
239
|
|
133
240
|
[Compare v0.1.0...v0.2.0](https://github.com/dry-rb/dry-core/compare/v0.1.0...v0.2.0)
|
134
241
|
|
135
|
-
|
242
|
+
## 0.1.0 2016-09-17
|
136
243
|
|
137
244
|
Initial release
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015-2020 dry-rb team
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,47 +1,29 @@
|
|
1
|
-
[gitter]: https://gitter.im/dry-rb/chat
|
2
1
|
[gem]: https://rubygems.org/gems/dry-core
|
3
|
-
[
|
4
|
-
[
|
5
|
-
[
|
2
|
+
[actions]: https://github.com/dry-rb/dry-core/actions
|
3
|
+
[codacy]: https://www.codacy.com/gh/dry-rb/dry-core
|
4
|
+
[chat]: https://dry-rb.zulipchat.com
|
5
|
+
[inchpages]: http://inch-ci.org/github/dry-rb/dry-core
|
6
6
|
|
7
|
-
# dry-core
|
7
|
+
# dry-core [![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://
|
10
|
-
[![
|
11
|
-
[![
|
12
|
-
[![
|
13
|
-
[![
|
14
|
-
![No monkey-patches](https://img.shields.io/badge/monkey--patches-0-brightgreen.svg)
|
9
|
+
[![Gem Version](https://badge.fury.io/rb/dry-core.svg)][gem]
|
10
|
+
[![CI Status](https://github.com/dry-rb/dry-core/workflows/ci/badge.svg)][actions]
|
11
|
+
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/40946292b9094624beec604a149a6023)][codacy]
|
12
|
+
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/40946292b9094624beec604a149a6023)][codacy]
|
13
|
+
[![Inline docs](http://inch-ci.org/github/dry-rb/dry-core.svg?branch=master)][inchpages]
|
15
14
|
|
16
|
-
|
15
|
+
## Links
|
17
16
|
|
18
|
-
|
17
|
+
* [User documentation](http://dry-rb.org/gems/dry-core)
|
18
|
+
* [API documentation](http://rubydoc.info/gems/dry-core)
|
19
19
|
|
20
|
-
|
20
|
+
## Supported Ruby versions
|
21
21
|
|
22
|
-
|
23
|
-
gem 'dry-core'
|
24
|
-
```
|
25
|
-
|
26
|
-
And then execute:
|
27
|
-
|
28
|
-
$ bundle
|
29
|
-
|
30
|
-
Or install it yourself as:
|
31
|
-
|
32
|
-
$ gem install dry-core
|
33
|
-
|
34
|
-
## Development
|
35
|
-
|
36
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
37
|
-
|
38
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
39
|
-
|
40
|
-
## Contributing
|
41
|
-
|
42
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/dry-rb/dry-core.
|
22
|
+
This library officially supports the following Ruby versions:
|
43
23
|
|
24
|
+
* MRI >= `2.5`
|
25
|
+
* jruby >= `9.2`
|
44
26
|
|
45
27
|
## License
|
46
28
|
|
47
|
-
|
29
|
+
See `LICENSE` file.
|
data/dry-core.gemspec
CHANGED
@@ -1,34 +1,36 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# this file is managed by dry-rb/devtools project
|
3
|
+
|
4
|
+
lib = File.expand_path('lib', __dir__)
|
2
5
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
6
|
require 'dry/core/version'
|
4
7
|
|
5
8
|
Gem::Specification.new do |spec|
|
6
9
|
spec.name = 'dry-core'
|
7
|
-
spec.
|
8
|
-
spec.
|
9
|
-
spec.
|
10
|
+
spec.authors = ["Nikita Shilnikov"]
|
11
|
+
spec.email = ["fg@flashgordon.ru"]
|
12
|
+
spec.license = 'MIT'
|
13
|
+
spec.version = Dry::Core::VERSION.dup
|
10
14
|
|
11
|
-
spec.summary =
|
15
|
+
spec.summary = "A toolset of small support modules used throughout the dry-rb ecosystem"
|
12
16
|
spec.description = spec.summary
|
13
|
-
spec.homepage = 'https://
|
14
|
-
spec.
|
17
|
+
spec.homepage = 'https://dry-rb.org/gems/dry-core'
|
18
|
+
spec.files = Dir["CHANGELOG.md", "LICENSE", "README.md", "dry-core.gemspec", "lib/**/*"]
|
19
|
+
spec.bindir = 'bin'
|
20
|
+
spec.executables = []
|
21
|
+
spec.require_paths = ['lib']
|
15
22
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
else
|
21
|
-
raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
|
22
|
-
end
|
23
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
24
|
+
spec.metadata['changelog_uri'] = 'https://github.com/dry-rb/dry-core/blob/master/CHANGELOG.md'
|
25
|
+
spec.metadata['source_code_uri'] = 'https://github.com/dry-rb/dry-core'
|
26
|
+
spec.metadata['bug_tracker_uri'] = 'https://github.com/dry-rb/dry-core/issues'
|
23
27
|
|
24
|
-
spec.
|
25
|
-
|
26
|
-
|
27
|
-
spec.
|
28
|
-
spec.required_ruby_version = '>= 2.1.0'
|
29
|
-
spec.add_runtime_dependency 'concurrent-ruby', '~> 1.0'
|
28
|
+
spec.required_ruby_version = ">= 2.5.0"
|
29
|
+
|
30
|
+
# to update dependencies edit project.yml
|
31
|
+
spec.add_runtime_dependency "concurrent-ruby", "~> 1.0"
|
30
32
|
|
31
|
-
spec.add_development_dependency
|
32
|
-
spec.add_development_dependency
|
33
|
-
spec.add_development_dependency
|
33
|
+
spec.add_development_dependency "bundler"
|
34
|
+
spec.add_development_dependency "rake"
|
35
|
+
spec.add_development_dependency "rspec"
|
34
36
|
end
|
data/lib/dry-core.rb
CHANGED
data/lib/dry/core.rb
CHANGED
data/lib/dry/core/cache.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'dry/core/constants'
|
2
4
|
require 'dry/core/errors'
|
3
5
|
|
@@ -49,22 +51,42 @@ module Dry
|
|
49
51
|
# defines :one, :two, type: Dry::Types['strict.int']
|
50
52
|
# end
|
51
53
|
#
|
52
|
-
|
53
|
-
|
54
|
+
# @example with coercion using Proc
|
55
|
+
#
|
56
|
+
# class Bar
|
57
|
+
# extend Dry::Core::ClassAttributes
|
58
|
+
#
|
59
|
+
# defines :one, coerce: proc { |value| value.to_s }
|
60
|
+
# end
|
61
|
+
#
|
62
|
+
# @example with coercion using dry-types
|
63
|
+
#
|
64
|
+
# class Bar
|
65
|
+
# extend Dry::Core::ClassAttributes
|
66
|
+
#
|
67
|
+
# defines :one, coerce: Dry::Types['coercible.string']
|
68
|
+
# end
|
69
|
+
#
|
70
|
+
def defines(*args, type: ::Object, coerce: IDENTITY)
|
71
|
+
unless coerce.respond_to?(:call)
|
72
|
+
raise ::ArgumentError, "Non-callable coerce option: #{coerce.inspect}"
|
73
|
+
end
|
74
|
+
|
75
|
+
mod = ::Module.new do
|
54
76
|
args.each do |name|
|
55
|
-
|
56
|
-
ivar = "@#{name}"
|
77
|
+
ivar = :"@#{name}"
|
57
78
|
|
58
|
-
|
79
|
+
define_method(name) do |value = Undefined|
|
80
|
+
if Undefined.equal?(value)
|
59
81
|
if instance_variable_defined?(ivar)
|
60
82
|
instance_variable_get(ivar)
|
61
83
|
else
|
62
84
|
nil
|
63
85
|
end
|
86
|
+
elsif type === value
|
87
|
+
instance_variable_set(ivar, coerce.call(value))
|
64
88
|
else
|
65
|
-
raise InvalidClassAttributeValue.new(name, value)
|
66
|
-
|
67
|
-
instance_variable_set(ivar, value)
|
89
|
+
raise InvalidClassAttributeValue.new(name, value)
|
68
90
|
end
|
69
91
|
end
|
70
92
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Dry
|
2
4
|
module Core
|
3
5
|
# Class for generating more classes
|
@@ -70,8 +72,6 @@ module Dry
|
|
70
72
|
remove_const(name)
|
71
73
|
const_set(name, klass)
|
72
74
|
|
73
|
-
const_get(name).name if RUBY_VERSION < '2.4'
|
74
|
-
|
75
75
|
remove_const(name)
|
76
76
|
const_set(name, base)
|
77
77
|
end
|
@@ -81,11 +81,16 @@ module Dry
|
|
81
81
|
|
82
82
|
# @api private
|
83
83
|
def create_base(namespace, name, parent)
|
84
|
+
begin
|
85
|
+
namespace.const_get(name)
|
86
|
+
rescue NameError
|
87
|
+
end
|
88
|
+
|
84
89
|
if namespace.const_defined?(name, false)
|
85
90
|
existing = namespace.const_get(name)
|
86
91
|
|
87
92
|
unless existing <= parent
|
88
|
-
raise ParentClassMismatch, "#{
|
93
|
+
raise ParentClassMismatch, "#{existing.name} must be a subclass of #{parent.name}"
|
89
94
|
end
|
90
95
|
|
91
96
|
existing
|
data/lib/dry/core/constants.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'set'
|
2
4
|
|
3
5
|
module Dry
|
@@ -6,6 +8,7 @@ module Dry
|
|
6
8
|
#
|
7
9
|
# @example Just include this module to your class or module
|
8
10
|
# class Foo
|
11
|
+
# include Dry::Core::Constants
|
9
12
|
# def call(value = EMPTY_ARRAY)
|
10
13
|
# value.map(&:to_s)
|
11
14
|
# end
|
@@ -20,26 +23,33 @@ module Dry
|
|
20
23
|
# An empty list of options
|
21
24
|
EMPTY_OPTS = {}.freeze
|
22
25
|
# An empty set
|
23
|
-
EMPTY_SET = Set.new.freeze
|
26
|
+
EMPTY_SET = ::Set.new.freeze
|
24
27
|
# An empty string
|
25
28
|
EMPTY_STRING = ''.freeze
|
29
|
+
# Identity function
|
30
|
+
IDENTITY = (-> x { x }).freeze
|
26
31
|
|
27
32
|
# A special value you can use as a default to know if no arguments
|
28
|
-
# were passed to
|
33
|
+
# were passed to the method
|
29
34
|
#
|
30
35
|
# @example
|
31
36
|
# def method(value = Undefined)
|
32
|
-
# if value
|
37
|
+
# if Undefined.equal?(value)
|
33
38
|
# puts 'no args'
|
34
39
|
# else
|
35
40
|
# puts value
|
36
41
|
# end
|
37
42
|
# end
|
38
43
|
Undefined = Object.new.tap do |undefined|
|
44
|
+
# @api private
|
45
|
+
Self = -> { Undefined }
|
46
|
+
|
47
|
+
# @api public
|
39
48
|
def undefined.to_s
|
40
49
|
'Undefined'
|
41
50
|
end
|
42
51
|
|
52
|
+
# @api public
|
43
53
|
def undefined.inspect
|
44
54
|
'Undefined'
|
45
55
|
end
|
@@ -48,13 +58,13 @@ module Dry
|
|
48
58
|
# otherwise return the second arg or yield the block.
|
49
59
|
#
|
50
60
|
# @example
|
51
|
-
#
|
52
|
-
#
|
53
|
-
#
|
61
|
+
# def method(val = Undefined)
|
62
|
+
# 1 + Undefined.default(val, 2)
|
63
|
+
# end
|
54
64
|
#
|
55
65
|
def undefined.default(x, y = self)
|
56
|
-
if
|
57
|
-
if
|
66
|
+
if equal?(x)
|
67
|
+
if equal?(y)
|
58
68
|
yield
|
59
69
|
else
|
60
70
|
y
|
@@ -63,6 +73,36 @@ module Dry
|
|
63
73
|
x
|
64
74
|
end
|
65
75
|
end
|
76
|
+
|
77
|
+
# Map a non-undefined value
|
78
|
+
#
|
79
|
+
# @example
|
80
|
+
# def add_five(val = Undefined)
|
81
|
+
# Undefined.map(val) { |x| x + 5 }
|
82
|
+
# end
|
83
|
+
#
|
84
|
+
def undefined.map(value)
|
85
|
+
if equal?(value)
|
86
|
+
self
|
87
|
+
else
|
88
|
+
yield(value)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# @api public
|
93
|
+
def undefined.dup
|
94
|
+
self
|
95
|
+
end
|
96
|
+
|
97
|
+
# @api public
|
98
|
+
def undefined.clone
|
99
|
+
self
|
100
|
+
end
|
101
|
+
|
102
|
+
# @api public
|
103
|
+
def undefined.coalesce(*args)
|
104
|
+
args.find(Self) { |x| !equal?(x) }
|
105
|
+
end
|
66
106
|
end.freeze
|
67
107
|
|
68
108
|
def self.included(base)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'logger'
|
2
4
|
|
3
5
|
module Dry
|
@@ -15,7 +17,7 @@ module Dry
|
|
15
17
|
# def old_api; end
|
16
18
|
# def new_api; end
|
17
19
|
#
|
18
|
-
#
|
20
|
+
# deprecate :old_api, :new_api, message: "old_api is no-no"
|
19
21
|
# end
|
20
22
|
#
|
21
23
|
# @example You also can use this module for your custom messages
|
@@ -47,8 +49,8 @@ module Dry
|
|
47
49
|
# @api private
|
48
50
|
def deprecation_message(name, msg)
|
49
51
|
<<-MSG
|
50
|
-
#{
|
51
|
-
#{
|
52
|
+
#{name} is deprecated and will be removed in the next major version
|
53
|
+
#{msg}
|
52
54
|
MSG
|
53
55
|
end
|
54
56
|
|
@@ -70,7 +72,7 @@ module Dry
|
|
70
72
|
# @param [IO] output output stream
|
71
73
|
#
|
72
74
|
# @return [Logger]
|
73
|
-
def logger(output =
|
75
|
+
def logger(output = $stderr)
|
74
76
|
if defined?(@logger)
|
75
77
|
@logger
|
76
78
|
else
|
@@ -95,7 +97,7 @@ module Dry
|
|
95
97
|
@logger = output
|
96
98
|
else
|
97
99
|
@logger = Logger.new(output).tap do |logger|
|
98
|
-
logger.formatter = proc { |_, _, _, msg| "#{
|
100
|
+
logger.formatter = proc { |_, _, _, msg| "#{msg}\n" }
|
99
101
|
end
|
100
102
|
end
|
101
103
|
end
|
@@ -153,7 +155,7 @@ module Dry
|
|
153
155
|
undef_method old_name if method_defined?(old_name)
|
154
156
|
|
155
157
|
define_method(old_name) do |*args, &block|
|
156
|
-
mod.warn("#{
|
158
|
+
mod.warn("#{full_msg}\n#{STACK.()}")
|
157
159
|
__send__(new_name, *args, &block)
|
158
160
|
end
|
159
161
|
else
|
@@ -163,7 +165,7 @@ module Dry
|
|
163
165
|
undef_method old_name
|
164
166
|
|
165
167
|
define_method(old_name) do |*args, &block|
|
166
|
-
mod.warn("#{
|
168
|
+
mod.warn("#{full_msg}\n#{STACK.()}")
|
167
169
|
__send__(aliased_name, *args, &block)
|
168
170
|
end
|
169
171
|
end
|
@@ -187,7 +189,7 @@ module Dry
|
|
187
189
|
undef_method old_name if method_defined?(old_name)
|
188
190
|
|
189
191
|
define_method(old_name) do |*args, &block|
|
190
|
-
warn("#{
|
192
|
+
warn("#{full_msg}\n#{STACK.()}")
|
191
193
|
meth.call(*args, &block)
|
192
194
|
end
|
193
195
|
end
|
@@ -208,7 +210,7 @@ module Dry
|
|
208
210
|
mod = Module.new do
|
209
211
|
define_method(:const_missing) do |missing|
|
210
212
|
if missing == constant_name
|
211
|
-
warn("#{
|
213
|
+
warn("#{full_msg}\n#{STACK.()}")
|
212
214
|
value
|
213
215
|
else
|
214
216
|
super(missing)
|
data/lib/dry/core/errors.rb
CHANGED
data/lib/dry/core/extensions.rb
CHANGED
data/lib/dry/core/inflector.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Dry
|
2
4
|
module Core
|
3
5
|
# Helper module providing thin interface around an inflection backend.
|
@@ -36,8 +38,8 @@ module Dry
|
|
36
38
|
BACKENDS.inject(nil) do |backend, (_, (path, factory))|
|
37
39
|
backend || realize_backend(path, factory)
|
38
40
|
end || raise(LoadError,
|
39
|
-
|
40
|
-
|
41
|
+
'No inflector library could be found: '\
|
42
|
+
'please install either the `inflecto` or `activesupport` gem.')
|
41
43
|
end
|
42
44
|
|
43
45
|
# Set preferred backend
|
@@ -47,6 +49,7 @@ module Dry
|
|
47
49
|
if name && !BACKENDS.key?(name)
|
48
50
|
raise NameError, "Invalid inflector library selection: '#{name}'"
|
49
51
|
end
|
52
|
+
|
50
53
|
@inflector = name ? realize_backend(*BACKENDS[name]) : detect_backend
|
51
54
|
end
|
52
55
|
|
data/lib/dry/core/memoizable.rb
CHANGED
data/lib/dry/core/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nikita Shilnikov
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -28,62 +28,54 @@ dependencies:
|
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
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
|
-
version: '
|
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
|
-
version: '
|
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
|
-
version: '
|
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
|
-
version: '
|
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
|
-
version: '
|
69
|
-
description: A toolset of small support modules used throughout the dry-rb ecosystem
|
68
|
+
version: '0'
|
69
|
+
description: A toolset of small support modules used throughout the dry-rb ecosystem
|
70
70
|
email:
|
71
71
|
- fg@flashgordon.ru
|
72
72
|
executables: []
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
-
- ".gitignore"
|
77
|
-
- ".inch.yml"
|
78
|
-
- ".rspec"
|
79
|
-
- ".rubocop.yml"
|
80
|
-
- ".travis.yml"
|
81
76
|
- CHANGELOG.md
|
82
|
-
-
|
83
|
-
- Gemfile
|
84
|
-
- LICENSE.txt
|
77
|
+
- LICENSE
|
85
78
|
- README.md
|
86
|
-
- Rakefile
|
87
79
|
- dry-core.gemspec
|
88
80
|
- lib/dry-core.rb
|
89
81
|
- lib/dry/core.rb
|
@@ -98,11 +90,14 @@ files:
|
|
98
90
|
- lib/dry/core/inflector.rb
|
99
91
|
- lib/dry/core/memoizable.rb
|
100
92
|
- lib/dry/core/version.rb
|
101
|
-
homepage: https://
|
93
|
+
homepage: https://dry-rb.org/gems/dry-core
|
102
94
|
licenses:
|
103
95
|
- MIT
|
104
96
|
metadata:
|
105
97
|
allowed_push_host: https://rubygems.org
|
98
|
+
changelog_uri: https://github.com/dry-rb/dry-core/blob/master/CHANGELOG.md
|
99
|
+
source_code_uri: https://github.com/dry-rb/dry-core
|
100
|
+
bug_tracker_uri: https://github.com/dry-rb/dry-core/issues
|
106
101
|
post_install_message:
|
107
102
|
rdoc_options: []
|
108
103
|
require_paths:
|
@@ -111,16 +106,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
111
106
|
requirements:
|
112
107
|
- - ">="
|
113
108
|
- !ruby/object:Gem::Version
|
114
|
-
version: 2.
|
109
|
+
version: 2.5.0
|
115
110
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
111
|
requirements:
|
117
112
|
- - ">="
|
118
113
|
- !ruby/object:Gem::Version
|
119
114
|
version: '0'
|
120
115
|
requirements: []
|
121
|
-
|
122
|
-
rubygems_version: 2.7.5
|
116
|
+
rubygems_version: 3.1.4
|
123
117
|
signing_key:
|
124
118
|
specification_version: 4
|
125
|
-
summary: A toolset of small support modules used throughout the dry-rb ecosystem
|
119
|
+
summary: A toolset of small support modules used throughout the dry-rb ecosystem
|
126
120
|
test_files: []
|
data/.gitignore
DELETED
data/.inch.yml
DELETED
data/.rspec
DELETED
data/.rubocop.yml
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
AllCops:
|
2
|
-
TargetRubyVersion: 2.1
|
3
|
-
Exclude:
|
4
|
-
- 'dry-core.gemspec'
|
5
|
-
- 'spec/spec_helper.rb'
|
6
|
-
|
7
|
-
Style/SignalException:
|
8
|
-
Exclude:
|
9
|
-
- 'spec/**/*'
|
10
|
-
|
11
|
-
Style/RedundantSelf:
|
12
|
-
Exclude:
|
13
|
-
- 'lib/dry/core/deprecations.rb'
|
14
|
-
|
15
|
-
Metrics/LineLength:
|
16
|
-
Max: 110
|
17
|
-
|
18
|
-
Metrics/MethodLength:
|
19
|
-
Enabled: false
|
20
|
-
|
21
|
-
Style/FileName:
|
22
|
-
Exclude:
|
23
|
-
- 'lib/dry-core.rb'
|
24
|
-
|
25
|
-
Lint/AmbiguousRegexpLiteral:
|
26
|
-
Exclude:
|
27
|
-
- 'spec/**/*'
|
28
|
-
|
29
|
-
Style/BlockDelimiters:
|
30
|
-
Exclude:
|
31
|
-
- 'spec/**/*'
|
data/.travis.yml
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
dist: trusty
|
3
|
-
sudo: required
|
4
|
-
cache: bundler
|
5
|
-
bundler_args: --without benchmarks tools
|
6
|
-
after_success:
|
7
|
-
- '[ -d coverage ] && bundle exec codeclimate-test-reporter'
|
8
|
-
script:
|
9
|
-
- bundle exec rake
|
10
|
-
before_install:
|
11
|
-
- gem update --system
|
12
|
-
after_success:
|
13
|
-
- '[ -d coverage ] && bundle exec codeclimate-test-reporter'
|
14
|
-
rvm:
|
15
|
-
- 2.2.9
|
16
|
-
- 2.3.6
|
17
|
-
- 2.4.3
|
18
|
-
- 2.5.0
|
19
|
-
- jruby-9.1.15.0
|
20
|
-
env:
|
21
|
-
global:
|
22
|
-
- COVERAGE=true
|
23
|
-
- JRUBY_OPTS='--dev -J-Xmx1024M'
|
24
|
-
notifications:
|
25
|
-
email: false
|
26
|
-
webhooks:
|
27
|
-
urls:
|
28
|
-
- https://webhooks.gitter.im/e/19098b4253a72c9796db
|
29
|
-
on_success: change # options: [always|never|change] default: always
|
30
|
-
on_failure: always # options: [always|never|change] default: always
|
31
|
-
on_start: false # default: false
|
data/CONTRIBUTING.md
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# Issue Guidelines
|
2
|
-
|
3
|
-
## Reporting bugs
|
4
|
-
|
5
|
-
If you found a bug, report an issue and describe what's the expected behavior versus what actually happens. If the bug causes a crash, attach a full backtrace. If possible, a reproduction script showing the problem is highly appreciated.
|
6
|
-
|
7
|
-
## Reporting feature requests
|
8
|
-
|
9
|
-
Report a feature request **only after discourseing it first on [discourse.dry-rb.org](https://discourse.dry-rb.org)** where it was accepted. Please provide a concise description of the feature, don't link to a discourseion thread, and instead summarize what was discourseed.
|
10
|
-
|
11
|
-
## Reporting questions, support requests, ideas, concerns etc.
|
12
|
-
|
13
|
-
**PLEASE DON'T** - use [discourse.dry-rb.org](https://discourse.dry-rb.org) instead.
|
14
|
-
|
15
|
-
# Pull Request Guidelines
|
16
|
-
|
17
|
-
A Pull Request will only be accepted if it addresses a specific issue that was reported previously, or fixes typos, mistakes in documentation etc.
|
18
|
-
|
19
|
-
Other requirements:
|
20
|
-
|
21
|
-
1) Do not open a pull request if you can't provide tests along with it. If you have problems writing tests, ask for help in the related issue.
|
22
|
-
2) Follow the style conventions of the surrounding code. In most cases, this is standard ruby style.
|
23
|
-
3) Add API documentation if it's a new feature
|
24
|
-
4) Update API documentation if it changes an existing feature
|
25
|
-
5) Bonus points for sending a PR to [github.com/dry-rb/dry-rb.org](github.com/dry-rb/dry-rb.org) which updates user documentation and guides
|
26
|
-
|
27
|
-
# Asking for help
|
28
|
-
|
29
|
-
If these guidelines aren't helpful, and you're stuck, please post a message on [discourse.dry-rb.org](https://discourse.dry-rb.org).
|
data/Gemfile
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
gemspec
|
4
|
-
|
5
|
-
group :test do
|
6
|
-
if RUBY_VERSION >= '2.4'
|
7
|
-
gem 'activesupport'
|
8
|
-
else
|
9
|
-
gem 'activesupport', '~> 4.2'
|
10
|
-
end
|
11
|
-
gem 'inflecto', '~> 0.0', '>= 0.0.2'
|
12
|
-
gem 'codeclimate-test-reporter', require: false
|
13
|
-
gem 'simplecov', require: false
|
14
|
-
gem 'dry-types'
|
15
|
-
gem 'dry-inflector', git: 'https://github.com/dry-rb/dry-inflector', branch: 'master'
|
16
|
-
end
|
17
|
-
|
18
|
-
group :tools do
|
19
|
-
gem 'pry-byebug', platform: :mri
|
20
|
-
gem 'pry', platform: :jruby
|
21
|
-
gem 'rubocop'
|
22
|
-
end
|
data/LICENSE.txt
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2016 Nikita Shilnikov
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|