dry-core 0.4.2 → 0.4.4

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
- SHA1:
3
- metadata.gz: 1bb0fe21e198b946d0363a8a082f3c860605eb38
4
- data.tar.gz: d08019514eabec7e537e2a01138378295a62a75e
2
+ SHA256:
3
+ metadata.gz: 3a392bbea0fdae74dcaa2a99035e2b4d326d68a733ad8cbed5803c31cae028e5
4
+ data.tar.gz: 320c2059c1424a20eefd901c1f8f48da399ce3579441d546bab8b9dac7457f24
5
5
  SHA512:
6
- metadata.gz: 68b16b0ce816c94c9187d3721933aad533d5d8450c742b5e3659cdfc5dc77d6a63d3ae56f67c2278a3403382bace6af3396aefcb77f5f2a06053d3c16efb1d94
7
- data.tar.gz: 5d97a6f64702926e66aba7bf4d1727f143997cce3054d4c58f35890a4e344265e4f37492f6cc56aec80685bdefce9a4fd6a1bc8e3c802fbec6feaad76e99d90a
6
+ metadata.gz: 883649ce8aa3ed20709191569110e0f4969c614fd4baf72dc2fc80a47847f20493ffbda1d795da21e15289383eb55f3c77f4a8f367832b90f22021ffab7914d2
7
+ data.tar.gz: c7dee84cedde914a6a800ed6822c957d099c90ded80b558f9b1625ab6706cf85b273af73f6e5404320b1e46e7b58a3111ff7af9613c5b457e61dc00978ff9e28
@@ -7,12 +7,16 @@ after_success:
7
7
  - '[ -d coverage ] && bundle exec codeclimate-test-reporter'
8
8
  script:
9
9
  - bundle exec rake
10
+ before_install:
11
+ - gem update --system
12
+ after_success:
13
+ - '[ -d coverage ] && bundle exec codeclimate-test-reporter'
10
14
  rvm:
11
- - 2.1.10
12
- - 2.2.7
13
- - 2.3.4
14
- - 2.4.1
15
- - jruby-9.1.9.0
15
+ - 2.2.9
16
+ - 2.3.6
17
+ - 2.4.3
18
+ - 2.5.0
19
+ - jruby-9.1.15.0
16
20
  env:
17
21
  global:
18
22
  - COVERAGE=true
@@ -1,3 +1,20 @@
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
+
10
+ # v0.4.3 2018-02-03
11
+
12
+ ### Added
13
+
14
+ * `Dry::Core::DescendantsTracker` which is a maintained version of the [`descendants_tracker`](https://github.com/dkubb/descendants_tracker) gem (flash-gordon)
15
+
16
+ [Compare v0.4.2...v0.4.3](https://github.com/dry-rb/dry-core/compare/v0.4.2...0.4.3)
17
+
1
18
  # v0.4.2 2017-12-16
2
19
 
3
20
  ### Fixed
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
@@ -0,0 +1,76 @@
1
+ require 'concurrent/array'
2
+
3
+ module Dry
4
+ module Core
5
+ # An implementation of descendants tracker, heavily inspired
6
+ # by the descendants_tracker gem.
7
+ #
8
+ # @example
9
+ #
10
+ # class Base
11
+ # extend Dry::Core::DescendantsTracker
12
+ # end
13
+ #
14
+ # class A < Base
15
+ # end
16
+ #
17
+ # class B < Base
18
+ # end
19
+ #
20
+ # class C < A
21
+ # end
22
+ #
23
+ # Base.descendants # => [C, B, A]
24
+ # A.descendants # => [C]
25
+ # B.descendants # => []
26
+ #
27
+ module DescendantsTracker
28
+ class << self
29
+ # @api private
30
+ def setup(target)
31
+ target.instance_variable_set(:@descendants, Concurrent::Array.new)
32
+ end
33
+
34
+ private
35
+
36
+ # @api private
37
+ def extended(base)
38
+ super
39
+
40
+ DescendantsTracker.setup(base)
41
+ end
42
+ end
43
+
44
+ # Return the descendants of this class
45
+ #
46
+ # @example
47
+ # descendants = Parent.descendants
48
+ #
49
+ # @return [Array<Class>]
50
+ #
51
+ # @api public
52
+ attr_reader :descendants
53
+
54
+ protected
55
+
56
+ # @api private
57
+ def add_descendant(descendant)
58
+ ancestor = superclass
59
+ if ancestor.respond_to?(:add_descendant, true)
60
+ ancestor.add_descendant(descendant)
61
+ end
62
+ descendants.unshift(descendant)
63
+ end
64
+
65
+ private
66
+
67
+ # @api private
68
+ def inherited(descendant)
69
+ super
70
+
71
+ DescendantsTracker.setup(descendant)
72
+ add_descendant(descendant)
73
+ end
74
+ end
75
+ end
76
+ end
@@ -1,5 +1,5 @@
1
1
  module Dry
2
2
  module Core
3
- VERSION = '0.4.2'.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.2
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: 2017-12-16 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
@@ -92,6 +92,7 @@ files:
92
92
  - lib/dry/core/class_builder.rb
93
93
  - lib/dry/core/constants.rb
94
94
  - lib/dry/core/deprecations.rb
95
+ - lib/dry/core/descendants_tracker.rb
95
96
  - lib/dry/core/errors.rb
96
97
  - lib/dry/core/extensions.rb
97
98
  - lib/dry/core/inflector.rb
@@ -117,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
118
  version: '0'
118
119
  requirements: []
119
120
  rubyforge_project:
120
- rubygems_version: 2.6.14
121
+ rubygems_version: 2.7.3
121
122
  signing_key:
122
123
  specification_version: 4
123
124
  summary: A toolset of small support modules used throughout the dry-rb ecosystem.