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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b4f56e04c1cdf9503a86498dafcd37a2e46d1c18d5a40e9974795cd656d183e
4
- data.tar.gz: a774b50a5616c40a6bac42240ae0e666b10d847bf083922bfd93921828f658e1
3
+ metadata.gz: 538785d6f230fed2829eb31c2eed7b4f878db06f3d69703329e571327abea700
4
+ data.tar.gz: 6df94708151283cf120d590581171931141f999d8bdace6a825d80f61ac220e4
5
5
  SHA512:
6
- metadata.gz: ab32eee7ff76b9176cd1fc80f0112c67918557d655dd24f043b65256c86fed3ab7469cb642ef31a75aa5a8e6c6abc9abc709f3591cac7b6daef9fee0def6454f
7
- data.tar.gz: 0a24c3dd493063e9046740e52d9a4e54e8e2df874577830c1c066dfcf27bfcb7a824a4d2da1ef55849e23806a0d7e3bfe37ca4ca796be3890dbff19ff0b4fd14
6
+ metadata.gz: 4ab27069408443161d3bed839e061e35ff0c683d3d9023d6834b1d45e48d44eb13eba350b3c7760312ace4eac3d83b8c008eada7878338fa017c96b195c02acc
7
+ data.tar.gz: 73c828d5271872b6b5a2b0cbf1d53075b3845ad36e82a90c7d12e35f7154a807c1320de5233eb9c26eeba35cf4078ed0b3fa5deb2b9bc7306adb26c10174d13a
@@ -1,137 +1,244 @@
1
- # v0.4.5 2018-03-14
1
+ ## 0.4.10 2020-11-19
2
+
2
3
 
3
4
  ### Added
4
5
 
5
- * `Dry::Core::Memoizable`, which provides a `memoize` macro for memoizing results of instance methods (timriley)
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.5...v0.4.5](https://github.com/dry-rb/dry-core/compare/v0.4.4...v0.4.5)
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
- * `deprecate_constant` overrides `Module#deprecate_constant` and issues a labeled message on accessing a deprecated constant (flash-gordon)
14
- * `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)
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
- # v0.4.3 2018-02-03
99
+ ## 0.4.3 2018-02-03
100
+
19
101
 
20
102
  ### Added
21
103
 
22
- * `Dry::Core::DescendantsTracker` which is a maintained version of the [`descendants_tracker`](https://github.com/dkubb/descendants_tracker) gem (flash-gordon)
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...0.4.3)
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
- * Class attributes now support private setters/getters (flash-gordon)
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
- # v0.4.1 2017-11-04
119
+ ## 0.4.1 2017-11-04
120
+
35
121
 
36
122
  ### Changed
37
123
 
38
- * Improved error message on invalid attribute value (GustavoCaso)
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
- # v0.4.0 2017-11-02
128
+ ## 0.4.0 2017-11-02
129
+
43
130
 
44
131
  ### Added
45
132
 
46
- * 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)
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
- class Foo
50
- extend Dry::Core::ClassAttributes
136
+ class Foo
137
+ extend Dry::Core::ClassAttributes
51
138
 
52
- defines :ruby_attr, type: Integer
53
- defines :dry_attr, type: Dry::Types['strict.int']
54
- end
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
- # v0.3.4 2017-09-29
147
+ ## 0.3.4 2017-09-29
148
+
60
149
 
61
150
  ### Fixed
62
151
 
63
- * `Deprecations` output is set to `$stderr` by default now (solnic)
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
- # v0.3.3 2017-08-31
157
+ ## 0.3.3 2017-08-31
158
+
68
159
 
69
160
  ### Fixed
70
161
 
71
- * The Deprecations module now shows the right caller line (flash-gordon)
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
- # v0.3.2 2017-08-31
167
+ ## 0.3.2 2017-08-31
168
+
76
169
 
77
170
  ### Added
78
171
 
79
- * Accept an existing logger object in `Dry::Core::Deprecations.set_logger!` (flash-gordon)
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
- # v0.3.1 2017-05-27
177
+ ## 0.3.1 2017-05-27
178
+
84
179
 
85
180
  ### Added
86
181
 
87
- * Support for building classes within an existing namespace (flash-gordon)
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
- # v0.3.0 2017-05-05
187
+ ## 0.3.0 2017-05-05
188
+
92
189
 
93
190
  ### Changed
94
191
 
95
- * 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)
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
- # v0.2.4 2017-01-26
196
+ ## 0.2.4 2017-01-26
197
+
100
198
 
101
199
  ### Fixed
102
200
 
103
- * Do not require deprecated method to be defined (flash-gordon)
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
- # v0.2.3 2016-12-30
206
+ ## 0.2.3 2016-12-30
207
+
108
208
 
109
209
  ### Fixed
110
210
 
111
- * Fix warnings on using uninitialized class attributes (flash-gordon)
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
- # v0.2.2 2016-12-30
216
+ ## 0.2.2 2016-12-30
217
+
116
218
 
117
219
  ### Added
118
220
 
119
- * `ClassAttributes` which provides `defines` method for defining get-or-set methods (flash-gordon)
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
- # v0.2.1 2016-11-18
226
+ ## 0.2.1 2016-11-18
227
+
124
228
 
125
229
  ### Added
126
230
 
127
- * `Constants` are now available in nested scopes (flash-gordon)
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
- # v0.2.0 2016-11-01
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
- # v0.1.0 2016-09-17
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
- [travis]: https://travis-ci.org/dry-rb/dry-core
4
- [code_climate]: https://codeclimate.com/github/dry-rb/dry-core
5
- [inch]: http://inch-ci.org/github/dry-rb/dry-core
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://img.shields.io/gem/v/dry-core.svg)][gem]
10
- [![Build Status](https://img.shields.io/travis/dry-rb/dry-core.svg)][travis]
11
- [![Code Climate](https://api.codeclimate.com/v1/badges/eebb0e969814744231e4/maintainability)][code_climate]
12
- [![Test Coverage](https://api.codeclimate.com/v1/badges/eebb0e969814744231e4/test_coverage)][code_climate]
13
- [![API Documentation Coverage](http://inch-ci.org/github/dry-rb/dry-core.svg)][inch]
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
- A collection of small modules used in the dry-rb ecosystem.
15
+ ## Links
17
16
 
18
- ## Installation
17
+ * [User documentation](http://dry-rb.org/gems/dry-core)
18
+ * [API documentation](http://rubydoc.info/gems/dry-core)
19
19
 
20
- Add this line to your application's Gemfile:
20
+ ## Supported Ruby versions
21
21
 
22
- ```ruby
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
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
29
+ See `LICENSE` file.
@@ -1,34 +1,36 @@
1
- lib = File.expand_path('../lib', __FILE__)
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.version = Dry::Core::VERSION
8
- spec.authors = ['Nikita Shilnikov']
9
- spec.email = ['fg@flashgordon.ru']
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 = 'A toolset of small support modules used throughout the dry-rb ecosystem.'
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://github.com/dry-rb/dry-core'
14
- spec.license = 'MIT'
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
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
- # to allow pushing to a single host or delete this section to allow pushing to any host.
18
- if spec.respond_to?(:metadata)
19
- spec.metadata['allowed_push_host'] = 'https://rubygems.org'
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.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|bin)/}) }
25
- spec.bindir = 'exe'
26
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
- spec.require_paths = ['lib']
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 'bundler', '~> 1.12'
32
- spec.add_development_dependency 'rake', '~> 10.0'
33
- spec.add_development_dependency 'rspec', '~> 3.0'
33
+ spec.add_development_dependency "bundler"
34
+ spec.add_development_dependency "rake"
35
+ spec.add_development_dependency "rspec"
34
36
  end
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/core'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/core/version'
2
4
 
3
5
  # :nodoc:
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'concurrent/map'
2
4
 
3
5
  module Dry
@@ -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
- def defines(*args, type: Object)
53
- mod = Module.new do
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
- define_method(name) do |value = Undefined|
56
- ivar = "@#{name}"
77
+ ivar = :"@#{name}"
57
78
 
58
- if value == Undefined
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) unless type === 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, "#{ existing.name } must be a subclass of #{ parent.name }"
93
+ raise ParentClassMismatch, "#{existing.name} must be a subclass of #{parent.name}"
89
94
  end
90
95
 
91
96
  existing
@@ -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 you method
33
+ # were passed to the method
29
34
  #
30
35
  # @example
31
36
  # def method(value = Undefined)
32
- # if value == Undefined
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
- # def method(val = Undefined)
52
- # 1 + Undefined.default(val, 2)
53
- # end
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 x.equal?(self)
57
- if y.equal?(self)
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
- # deprecate_method :old_api, :new_api, "old_api is no-no"
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
- #{ name } is deprecated and will be removed in the next major version
51
- #{ msg }
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 = nil)
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| "#{ msg }\n" }
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("#{ full_msg }\n#{ STACK.() }")
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("#{ full_msg }\n#{ STACK.() }")
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("#{ full_msg }\n#{ STACK.() }")
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("#{ full_msg }\n#{ STACK.() }")
213
+ warn("#{full_msg}\n#{STACK.()}")
212
214
  value
213
215
  else
214
216
  super(missing)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'concurrent/array'
2
4
 
3
5
  module Dry
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dry
2
4
  module Core
3
5
  class InvalidClassAttributeValue < StandardError
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'set'
2
4
 
3
5
  module Dry
@@ -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
- "No inflector library could be found: "\
40
- "please install either the `inflecto` or `activesupport` gem.")
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
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dry
2
4
  module Core
3
5
  module Memoizable
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dry
2
4
  module Core
3
- VERSION = '0.4.5'.freeze
5
+ VERSION = '0.4.10'.freeze
4
6
  end
5
7
  end
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.5
4
+ version: 0.4.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nikita Shilnikov
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-13 00:00:00.000000000 Z
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: '1.12'
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: '1.12'
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: '10.0'
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: '10.0'
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: '3.0'
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: '3.0'
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
- - CONTRIBUTING.md
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://github.com/dry-rb/dry-core
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.1.0
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
- rubyforge_project:
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
@@ -1,10 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- spec/examples.txt
data/.inch.yml DELETED
@@ -1,4 +0,0 @@
1
- files:
2
- excluded:
3
- - lib/dry/core.rb
4
- - lib/dry/core/version.rb
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format progress
2
- --color
3
- --require ./spec/spec_helper.rb
@@ -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/**/*'
@@ -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
@@ -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
@@ -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.
data/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task default: :spec