dry-core 0.4.3 → 0.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7b5db0cab5b5197fea7cda5ea4ed1e5fcdeaca63bcb736775c2f90c8bf5b4967
4
- data.tar.gz: d056e9fe44d76a4116afda3df87164abdab03d9cbf31d5b3abad52f4c2ef7724
3
+ metadata.gz: 3a392bbea0fdae74dcaa2a99035e2b4d326d68a733ad8cbed5803c31cae028e5
4
+ data.tar.gz: 320c2059c1424a20eefd901c1f8f48da399ce3579441d546bab8b9dac7457f24
5
5
  SHA512:
6
- metadata.gz: 02c968169fb2112878c74307fffb53e224370ab891f1722c3af2c3eef0cf08f76578e0ef4cf5ee51c12bba13b735d5b65c08b5160044d6104da40e80a844653c
7
- data.tar.gz: ca68db57997380c256d35f0bd74a2a9fbfb503b177c49a9061d903402e1d4a794c0936a8b2b8e65272f7f069b03e1e88f8199faf17340855b25f98008b0040cd
6
+ metadata.gz: 883649ce8aa3ed20709191569110e0f4969c614fd4baf72dc2fc80a47847f20493ffbda1d795da21e15289383eb55f3c77f4a8f367832b90f22021ffab7914d2
7
+ data.tar.gz: c7dee84cedde914a6a800ed6822c957d099c90ded80b558f9b1625ab6706cf85b273af73f6e5404320b1e46e7b58a3111ff7af9613c5b457e61dc00978ff9e28
@@ -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://img.shields.io/codeclimate/github/dry-rb/dry-core.svg)][code_climate]
12
- [![Test Coverage](https://img.shields.io/codeclimate/coverage/github/dry-rb/dry-core.svg)][code_climate]
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
 
@@ -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 deprecated_method_message(old, new = nil, msg = nil)
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.deprecated_method_message(
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.deprecated_method_message(
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
@@ -1,5 +1,5 @@
1
1
  module Dry
2
2
  module Core
3
- VERSION = '0.4.3'.freeze
3
+ VERSION = '0.4.4'.freeze
4
4
  end
5
5
  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.3
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-03 00:00:00.000000000 Z
11
+ date: 2018-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby