deprecations 2.0.0 → 2.0.1

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
  SHA1:
3
- metadata.gz: 8f1b32b67d233b85169a77021d6f79004ee7c71e
4
- data.tar.gz: 2e30cbd6b533b5282053117e232f970161e94f61
3
+ metadata.gz: 5a26b75a093acc26166b2d09ba9541eb26e35ab8
4
+ data.tar.gz: 5ae799df8b64aa9d2c9ec8a7be46c36fb454d5de
5
5
  SHA512:
6
- metadata.gz: 78d456e28cd58b8789578f6bd38a3a2014b764a2e6f3ff8701974310fa6cfc88896a56922e024960a52e2ac84854ff357e864798ed579ce7deb1fde51c8c1de0
7
- data.tar.gz: e3917883e117b8016fe92bc747a6c48bd8b0f9d753134bc4c482af9fd2084f0e496baed1b4704fe0d8c213734923ee4f6fa440a8b2e25309f588e4ef3a08c287
6
+ metadata.gz: 04beb30d068c578ff111dd807fd7fcc45cdd306a5e2cf5a4cbfe7a510ad84bc623f04e61add912c0aa39853a0dbaef59f3d77d88785ab717b2b85f08bf074890
7
+ data.tar.gz: 4f78d38bfb7e26a6a00c152506cf796932e6530028fc32cceabcbe3a2802f84e103fb74e396e434382ab302cce0637734998167d0f02a164c6d4239b0777b8f9
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## deprecations 2.0.1
2
+ - little code improvement
3
+
1
4
  ### deprecations 2.0.0
2
5
  - supports custom behavior
3
6
  - supports temporary behavior change
@@ -25,31 +25,35 @@ module Deprecations
25
25
 
26
26
  def as_behavior(arg)
27
27
  defined?(arg.call) ? arg : BEHAVIOR.fetch(arg) do
28
- raise(ArgumentError, "invalid parameter - behavior has to be #{valid_behavior} or need to respond to `call`")
28
+ raise(ArgumentError, "invalid parameter - behavior has to be #{valid_behaviors} or need to respond to `call`")
29
29
  end
30
30
  end
31
31
 
32
- def valid_behavior
32
+ def valid_behaviors
33
33
  BEHAVIOR.keys.map(&:inspect).join(' | ')
34
34
  end
35
35
 
36
- BEHAVIOR = {
37
- silence: ->(*){},
38
- raise: proc do |subject, alternative|
36
+ module Raise
37
+ def self.call(subject, alternative, _outdated)
39
38
  msg = "`#{subject}` is deprecated"
40
39
  alternative and msg << " - use #{alternative} instead"
41
- ex = ::DeprecationError.new(msg)
40
+ ex = DeprecationError.new(msg)
42
41
  ex.set_backtrace(caller(4))
43
42
  raise(ex)
44
- end,
45
- warn: proc do |subject, alternative, outdated |
43
+ end
44
+ end
45
+
46
+ module Warn
47
+ def self.call(subject, alternative, outdated)
46
48
  location = caller_locations(4, 1).last and location = "#{location.path}:#{location.lineno}: "
47
49
  msg = "#{location}[DEPRECATION] `#{subject}` is deprecated"
48
50
  msg << (outdated ? " and will be outdated #{outdated}." : '.')
49
51
  alternative and msg << " Please use `#{alternative}` instead."
50
52
  ::Kernel.warn(msg)
51
53
  end
52
- }
54
+ end
55
+
56
+ BEHAVIOR = {silence: ->(*){}, raise: Raise, warn: Warn}
53
57
 
54
58
  end
55
59
  end
@@ -1,3 +1,3 @@
1
1
  module Deprecations
2
- VERSION = '2.0.0'
2
+ VERSION = '2.0.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deprecations
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Blumtritt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-17 00:00:00.000000000 Z
11
+ date: 2015-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake