dry-core 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +2 -2
- data/lib/dry/core/constants.rb +20 -0
- data/lib/dry/core/deprecations.rb +29 -3
- data/lib/dry/core/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a392bbea0fdae74dcaa2a99035e2b4d326d68a733ad8cbed5803c31cae028e5
|
4
|
+
data.tar.gz: 320c2059c1424a20eefd901c1f8f48da399ce3579441d546bab8b9dac7457f24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 883649ce8aa3ed20709191569110e0f4969c614fd4baf72dc2fc80a47847f20493ffbda1d795da21e15289383eb55f3c77f4a8f367832b90f22021ffab7914d2
|
7
|
+
data.tar.gz: c7dee84cedde914a6a800ed6822c957d099c90ded80b558f9b1625ab6706cf85b273af73f6e5404320b1e46e7b58a3111ff7af9613c5b457e61dc00978ff9e28
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
# v0.4.4 2018-02-10
|
2
|
+
|
3
|
+
### Added
|
4
|
+
|
5
|
+
* `deprecate_constant` overrides `Module#deprecate_constant` and issues a labeled message on accessing a deprecated constant (flash-gordon)
|
6
|
+
* `Undefined.default` which accepts two arguments and returns the first if it's not `Undefiend`; otherwise, returns the second one or yields a block (flash-gordon)
|
7
|
+
|
8
|
+
[Compare v0.4.3...v0.4.4](https://github.com/dry-rb/dry-core/compare/v0.4.3...v0.4.4)
|
9
|
+
|
1
10
|
# v0.4.3 2018-02-03
|
2
11
|
|
3
12
|
### Added
|
data/README.md
CHANGED
@@ -8,8 +8,8 @@
|
|
8
8
|
|
9
9
|
[![Gem Version](https://img.shields.io/gem/v/dry-core.svg)][gem]
|
10
10
|
[![Build Status](https://img.shields.io/travis/dry-rb/dry-core.svg)][travis]
|
11
|
-
[![Code Climate](https://
|
12
|
-
[![Test Coverage](https://
|
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
13
|
[![API Documentation Coverage](http://inch-ci.org/github/dry-rb/dry-core.svg)][inch]
|
14
14
|
![No monkey-patches](https://img.shields.io/badge/monkey--patches-0-brightgreen.svg)
|
15
15
|
|
data/lib/dry/core/constants.rb
CHANGED
@@ -43,6 +43,26 @@ module Dry
|
|
43
43
|
def undefined.inspect
|
44
44
|
'Undefined'
|
45
45
|
end
|
46
|
+
|
47
|
+
# Pick a value, if the first argument is not Undefined, return it back,
|
48
|
+
# otherwise return the second arg or yield the block.
|
49
|
+
#
|
50
|
+
# @example
|
51
|
+
# def method(val = Undefined)
|
52
|
+
# 1 + Undefined.default(val, 2)
|
53
|
+
# end
|
54
|
+
#
|
55
|
+
def undefined.default(x, y = self)
|
56
|
+
if x.equal?(self)
|
57
|
+
if y.equal?(self)
|
58
|
+
yield
|
59
|
+
else
|
60
|
+
y
|
61
|
+
end
|
62
|
+
else
|
63
|
+
x
|
64
|
+
end
|
65
|
+
end
|
46
66
|
end.freeze
|
47
67
|
|
48
68
|
def self.included(base)
|
@@ -53,7 +53,7 @@ module Dry
|
|
53
53
|
end
|
54
54
|
|
55
55
|
# @api private
|
56
|
-
def
|
56
|
+
def deprecated_name_message(old, new = nil, msg = nil)
|
57
57
|
if new
|
58
58
|
deprecation_message(old, <<-MSG)
|
59
59
|
Please use #{new} instead.
|
@@ -142,7 +142,7 @@ module Dry
|
|
142
142
|
# @param [Symbol] new_name replacement (not required)
|
143
143
|
# @option [String] message optional deprecation message
|
144
144
|
def deprecate(old_name, new_name = nil, message: nil)
|
145
|
-
full_msg = Deprecations.
|
145
|
+
full_msg = Deprecations.deprecated_name_message(
|
146
146
|
"#{self.name}##{old_name}",
|
147
147
|
new_name ? "#{self.name}##{new_name}" : nil,
|
148
148
|
message
|
@@ -175,7 +175,7 @@ module Dry
|
|
175
175
|
# @param [Symbol] new_name replacement (not required)
|
176
176
|
# @option [String] message optional deprecation message
|
177
177
|
def deprecate_class_method(old_name, new_name = nil, message: nil)
|
178
|
-
full_msg = Deprecations.
|
178
|
+
full_msg = Deprecations.deprecated_name_message(
|
179
179
|
"#{self.name}.#{old_name}",
|
180
180
|
new_name ? "#{self.name}.#{new_name}" : nil,
|
181
181
|
message
|
@@ -192,6 +192,32 @@ module Dry
|
|
192
192
|
end
|
193
193
|
end
|
194
194
|
end
|
195
|
+
|
196
|
+
# Mark a constant as deprecated
|
197
|
+
# @param [Symbol] constant_name constant name to be deprecated
|
198
|
+
# @option [String] message optional deprecation message
|
199
|
+
def deprecate_constant(constant_name, message: nil)
|
200
|
+
value = const_get(constant_name)
|
201
|
+
remove_const(constant_name)
|
202
|
+
|
203
|
+
full_msg = Deprecations.deprecated_name_message(
|
204
|
+
"#{self.name}::#{constant_name}",
|
205
|
+
message
|
206
|
+
)
|
207
|
+
|
208
|
+
mod = Module.new do
|
209
|
+
define_method(:const_missing) do |missing|
|
210
|
+
if missing == constant_name
|
211
|
+
warn("#{ full_msg }\n#{ STACK.() }")
|
212
|
+
value
|
213
|
+
else
|
214
|
+
super(missing)
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
extend(mod)
|
220
|
+
end
|
195
221
|
end
|
196
222
|
end
|
197
223
|
end
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nikita Shilnikov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|