deprecations 2.0.3 → 2.0.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: c39b994d98f890a8e7e42388c75931ba422920a1
4
- data.tar.gz: 167070ffd16591babb39ae98cff8da9ee70b0e25
2
+ SHA256:
3
+ metadata.gz: d98430ec3094db3b30af3b96a693db71e2968d3fa2dda4fb92bdaacf67e0e8f8
4
+ data.tar.gz: 0bf5b46d38582b06aa63fc697b46539a44b376d4b207ce495e305fe70e587753
5
5
  SHA512:
6
- metadata.gz: 0a6e2929127ab9c95b6366efcc9015fe70af6a4828b67664424370ecd440d54773066f042b03168c883e7a877786fe47fe54a59e5037688dbd90ca9324d76031
7
- data.tar.gz: e320c10e966388888810a1eb670dc1f4dbd0431c566e759bae48cbf2a4c66bdde1043b126aa7b7154b068d9f245b81d1188c48912f02181d559db239e22d82c0
6
+ metadata.gz: 8ef90c37e7050de756e4f1c463be6813aedc2b4d24e374938d4ce29d744dabe11fd64d721c6ac2cd3493b8c76f1401ff4c73f7e00c09e152ab90f03e89892f55
7
+ data.tar.gz: '045540686602609ee4bf04ff1a862b5cb9f1da9027d839d55da66a458caaa8f7ac94404879c0cb5c33a002387a8df49f083987c73a62319ebeb554557e3a3baa'
data/Gemfile CHANGED
@@ -1,2 +1 @@
1
- source 'https://rubygems.org'
2
- gemspec
1
+ source('https://rubygems.org'){ gemspec }
data/Guardfile CHANGED
@@ -4,9 +4,9 @@ guard(
4
4
  spec_paths: ['spec'],
5
5
  failed_mode: :focus,
6
6
  all_on_start: true,
7
- all_after_pass: true,
7
+ all_after_pass: true
8
8
  ) do
9
- watch(%r[^spec/.+_spec.rb$])
10
- watch(%r[^lib/.+.rb$]){ 'spec' }
11
- watch(%r[^spec/spec_helper]){ 'spec' }
9
+ watch(%r{^spec/.+_spec.rb$})
10
+ watch(%r{^lib/.+.rb$}){ 'spec' }
11
+ watch(%r{^spec/spec_helper}){ 'spec' }
12
12
  end
data/README.md CHANGED
@@ -2,8 +2,6 @@
2
2
 
3
3
  This gem provides transparent declaration of deprecated methods and classes. It's easy, small, has no dependencies and no overhead.
4
4
 
5
- [![Code Climate](https://codeclimate.com/github/mblumtritt/deprecations.png)](https://codeclimate.com/github/mblumtritt/deprecations)
6
-
7
5
  ## Installation
8
6
 
9
7
  The simplest way to install Deprecations gem is to use [Bundler](http://gembundler.com/).
@@ -61,7 +59,7 @@ Marking a complete class as deprecated will present the deprecation warning when
61
59
  ```ruby
62
60
  class MySample
63
61
  deprecated!
64
-
62
+
65
63
  # some more code here...
66
64
  end
67
65
  ```
data/deprecations.gemspec CHANGED
@@ -1,24 +1,32 @@
1
1
  require File.expand_path('../lib/deprecations/version', __FILE__)
2
2
 
3
- GemSpec = Gem::Specification.new do |spec|
4
- spec.required_rubygems_version = Gem::Requirement.new('>= 1.3.6')
5
- spec.platform = Gem::Platform::RUBY
6
- spec.required_ruby_version = '>= 2.0.0'
3
+ Gem::Specification.new do |spec|
7
4
  spec.name = spec.rubyforge_project = 'deprecations'
8
5
  spec.version = Deprecations::VERSION
9
- spec.authors = ['Mike Blumtritt']
10
- spec.email = %w[mike.blumtritt@injixo.com]
11
6
  spec.summary = 'Deprecation support for your project.'
12
- spec.description = "This gem provides transparent declaration of deprecated methods and classes. "\
13
- "It's easy, small, has no dependencies and no overhead."
7
+ spec.description = <<~EOS
8
+ This gem provides transparent declaration of deprecated methods and classes.
9
+ It's easy, small, has no dependencies and no overhead.
10
+ EOS
11
+ spec.author = 'Mike Blumtritt'
12
+ spec.email = 'mike.blumtritt@invision.de'
14
13
  spec.homepage = 'https://github.com/mblumtritt/deprecations'
15
- spec.licenses = ['MIT']
16
- spec.date = Time.now.strftime('%Y-%m-%d')
14
+ spec.metadata = {'issue_tracker' => 'https://github.com/mblumtritt/deprecations/issues'}
15
+
16
+ spec.add_development_dependency 'bundler', '~> 1.11'
17
+ spec.add_development_dependency 'rake', '~> 10.1', '>= 10.1.1'
18
+ spec.add_development_dependency 'rspec', '~> 3.0', '>= 3.0.0'
19
+
20
+ spec.platform = Gem::Platform::RUBY
21
+ spec.required_ruby_version = '>= 2.0.0'
22
+ spec.required_rubygems_version = Gem::Requirement.new('>= 1.3.6')
23
+
17
24
  spec.require_paths = %w[lib]
18
- spec.files = %x[git ls-files].split($/)
19
- spec.test_files = spec.files.grep(%r[^spec/])
20
- spec.extra_rdoc_files = %w[README.md CHANGELOG.md]
21
- spec.has_rdoc = false # TODO!
22
- spec.add_development_dependency 'rake'
23
- spec.add_development_dependency 'rspec', '>= 3.0.0'
25
+
26
+ all_files = %x(git ls-files -z).split(0.chr)
27
+ spec.test_files = all_files.grep(%r{^(spec|test)/})
28
+ spec.files = all_files - spec.test_files
29
+
30
+ spec.has_rdoc = false
31
+ spec.extra_rdoc_files = %w(README.md)
24
32
  end
@@ -1,6 +1,5 @@
1
1
  module Deprecations
2
2
  class << self
3
-
4
3
  def behavior
5
4
  BEHAVIOR.key(@behavior) || @behavior
6
5
  end
@@ -11,7 +10,7 @@ module Deprecations
11
10
 
12
11
  def set_behavior(behavior)
13
12
  behavior = as_behavior(behavior)
14
- block_given? or raise(ArgumentError, 'block expected')
13
+ raise(ArgumentError, 'block expected') unless block_given?
15
14
  current_behavior = @behavior
16
15
  begin
17
16
  @behavior = behavior
@@ -24,8 +23,13 @@ module Deprecations
24
23
  private
25
24
 
26
25
  def as_behavior(arg)
27
- defined?(arg.call) ? arg : BEHAVIOR.fetch(arg) do
28
- raise(ArgumentError, "invalid parameter - behavior has to be #{valid_behaviors} or need to respond to `call`")
26
+ return arg if defined?(arg.call)
27
+ BEHAVIOR.fetch(arg) do
28
+ raise(
29
+ ArgumentError,
30
+ 'invalid parameter - behavior has to be' \
31
+ "#{valid_behaviors} or need to respond to `call`"
32
+ )
29
33
  end
30
34
  end
31
35
 
@@ -36,8 +40,8 @@ module Deprecations
36
40
  module Raise
37
41
  def self.call(subject, alternative, _outdated)
38
42
  msg = "`#{subject}` is deprecated"
39
- alternative and msg << " - use #{alternative} instead"
40
- ex = DeprecationError.new(msg)
43
+ msg << " - use #{alternative} instead" if alternative
44
+ ex = Error.new(msg)
41
45
  ex.set_backtrace(caller(4))
42
46
  raise(ex)
43
47
  end
@@ -45,15 +49,15 @@ module Deprecations
45
49
 
46
50
  module Warn
47
51
  def self.call(subject, alternative, outdated)
48
- location = caller_locations(4, 1).last and location = "#{location.path}:#{location.lineno}: "
52
+ location = caller_locations(4, 1)[-1]
53
+ location = "#{location.path}:#{location.lineno}: " if location
49
54
  msg = "#{location}[DEPRECATION] `#{subject}` is deprecated"
50
55
  msg << (outdated ? " and will be outdated #{outdated}." : '.')
51
- alternative and msg << " Please use `#{alternative}` instead."
56
+ msg << " Please use `#{alternative}` instead." if alternative
52
57
  ::Kernel.warn(msg)
53
58
  end
54
59
  end
55
60
 
56
- BEHAVIOR = {silence: ->(*){}, raise: Raise, warn: Warn}
57
-
61
+ BEHAVIOR = {silence: ->(*){ }, raise: Raise, warn: Warn}
58
62
  end
59
63
  end
@@ -1,7 +1,6 @@
1
1
  module Deprecations
2
2
  class << self
3
3
  private
4
-
5
4
  def infect(mod)
6
5
  mod.extend(ClassMethods)
7
6
  mod.send(:include, InstanceMethods)
@@ -18,21 +17,20 @@ module Deprecations
18
17
  undef_method(method.name)
19
18
  define_method(method.name) do |*a, &b|
20
19
  decorated = Class === self ? "#{self}." : "#{defining_context}#"
21
- Deprecations.call(
22
- "#{decorated}#{::Kernel.__method__}",
23
- UnboundMethod === alternative ? "#{decorated}#{alternative.name}" : alternative,
24
- outdated
25
- )
20
+ alternative = "#{decorated}#{alternative.name}" if UnboundMethod === alternative
21
+ Deprecations.call("#{decorated}#{::Kernel.__method__}", alternative, outdated)
26
22
  method.bind(self).call(*a, &b)
27
23
  end
28
24
  end
29
25
 
30
- def __method_not_found!(method_name)
31
- raise(NameError, "undefined method `#{method_name}` for class `#{self}`")
26
+ def __method_checked(method_name)
27
+ __method(method_name) or raise(
28
+ NameError, "undefined method `#{method_name}` for class `#{self}`"
29
+ )
32
30
  end
33
31
 
34
32
  def __method_alternative(alternative)
35
- Symbol === alternative ? (__method(alternative) or __method_not_found!(alternative)) : alternative
33
+ Symbol === alternative ? __method_checked(alternative) : alternative
36
34
  end
37
35
  end
38
36
 
@@ -42,7 +40,7 @@ module Deprecations
42
40
 
43
41
  def deprecated(method_name, alternative = nil, outdated = nil)
44
42
  __method_deprecated!(
45
- (__method(method_name) or __method_not_found!(method_name)),
43
+ __method_checked(method_name),
46
44
  __method_alternative(alternative),
47
45
  outdated
48
46
  )
@@ -54,7 +52,9 @@ module Deprecations
54
52
  include Helper
55
53
 
56
54
  def deprecated(method_name, alternative = nil, outdated = nil)
57
- m = __method(method_name) or return singleton_class.send(:deprecated, method_name, alternative, outdated)
55
+ m = __method(method_name) or return singleton_class.send(
56
+ :deprecated, method_name, alternative, outdated
57
+ )
58
58
  __method_deprecated!(m, __method_alternative(alternative), outdated)
59
59
  end
60
60
 
@@ -1,3 +1,3 @@
1
1
  module Deprecations
2
- VERSION = '2.0.3'
2
+ VERSION = '2.0.4'
3
3
  end
data/lib/deprecations.rb CHANGED
@@ -3,6 +3,8 @@ module Deprecations
3
3
  require_relative 'deprecations/extension'
4
4
  require_relative 'deprecations/behavior'
5
5
 
6
+ Error = Class.new(ScriptError)
7
+
6
8
  def self.call(subject, alternative, outdated)
7
9
  @behavior.call(subject, alternative, outdated)
8
10
  self
@@ -11,4 +13,4 @@ module Deprecations
11
13
  self.behavior = :warn
12
14
  end
13
15
 
14
- DeprecationError = Class.new(ScriptError)
16
+ DeprecationError = Deprecations::Error
@@ -60,15 +60,15 @@ RSpec.describe Deprecations do
60
60
  subject{ Deprecations.call('Bad#method', 'Bad#alternative', 'after next version') }
61
61
 
62
62
  it 'raises a Deprecations::Error' do
63
- expect{ subject }.to raise_error(DeprecationError)
63
+ expect{ subject }.to raise_error(Deprecations::Error)
64
64
  end
65
65
 
66
66
  it 'points to the deprecated method' do
67
- expect{ subject }.to raise_error(DeprecationError, /Bad#method.*deprecated/)
67
+ expect{ subject }.to raise_error(Deprecations::Error, /Bad#method.*deprecated/)
68
68
  end
69
69
 
70
70
  it 'suggests the alternative method' do
71
- expect{ subject }.to raise_error(DeprecationError, /Bad#alternative.*instead/)
71
+ expect{ subject }.to raise_error(Deprecations::Error, /Bad#alternative.*instead/)
72
72
  end
73
73
  end
74
74
 
@@ -139,13 +139,19 @@ RSpec.describe Deprecations do
139
139
  end
140
140
 
141
141
  it 'calls the handler with correct subject' do
142
- expect(Deprecations).to receive(:call).once.with("#{subject}#foo", anything, anything)
142
+ expect(Deprecations).to receive(:call)
143
+ .once
144
+ .with("#{subject}#foo", anything, anything)
143
145
  end
144
146
  it 'calls the handler with correct alternative method' do
145
- expect(Deprecations).to receive(:call).once.with(anything, "#{subject}#bar", anything)
147
+ expect(Deprecations).to receive(:call)
148
+ .once
149
+ .with(anything, "#{subject}#bar", anything)
146
150
  end
147
151
  it 'calls the handler with a comment' do
148
- expect(Deprecations).to receive(:call).once.with(anything, anything, 'next version')
152
+ expect(Deprecations).to receive(:call)
153
+ .once
154
+ .with(anything, anything, 'next version')
149
155
  end
150
156
  end
151
157
 
metadata CHANGED
@@ -1,33 +1,56 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deprecations
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.0.4
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-12-26 00:00:00.000000000 Z
11
+ date: 2018-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rake
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.1'
17
34
  - - ">="
18
35
  - !ruby/object:Gem::Version
19
- version: '0'
36
+ version: 10.1.1
20
37
  type: :development
21
38
  prerelease: false
22
39
  version_requirements: !ruby/object:Gem::Requirement
23
40
  requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '10.1'
24
44
  - - ">="
25
45
  - !ruby/object:Gem::Version
26
- version: '0'
46
+ version: 10.1.1
27
47
  - !ruby/object:Gem::Dependency
28
48
  name: rspec
29
49
  requirement: !ruby/object:Gem::Requirement
30
50
  requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '3.0'
31
54
  - - ">="
32
55
  - !ruby/object:Gem::Version
33
56
  version: 3.0.0
@@ -35,24 +58,24 @@ dependencies:
35
58
  prerelease: false
36
59
  version_requirements: !ruby/object:Gem::Requirement
37
60
  requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '3.0'
38
64
  - - ">="
39
65
  - !ruby/object:Gem::Version
40
66
  version: 3.0.0
41
- description: This gem provides transparent declaration of deprecated methods and classes.
67
+ description: |
68
+ This gem provides transparent declaration of deprecated methods and classes.
42
69
  It's easy, small, has no dependencies and no overhead.
43
- email:
44
- - mike.blumtritt@injixo.com
70
+ email: mike.blumtritt@invision.de
45
71
  executables: []
46
72
  extensions: []
47
73
  extra_rdoc_files:
48
74
  - README.md
49
- - CHANGELOG.md
50
75
  files:
51
76
  - ".gitignore"
52
- - CHANGELOG.md
53
77
  - Gemfile
54
78
  - Guardfile
55
- - LICENSE
56
79
  - README.md
57
80
  - Rakefile
58
81
  - deprecations.gemspec
@@ -65,9 +88,9 @@ files:
65
88
  - spec/deprecations_spec.rb
66
89
  - spec/spec_helper.rb
67
90
  homepage: https://github.com/mblumtritt/deprecations
68
- licenses:
69
- - MIT
70
- metadata: {}
91
+ licenses: []
92
+ metadata:
93
+ issue_tracker: https://github.com/mblumtritt/deprecations/issues
71
94
  post_install_message:
72
95
  rdoc_options: []
73
96
  require_paths:
@@ -84,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
107
  version: 1.3.6
85
108
  requirements: []
86
109
  rubyforge_project: deprecations
87
- rubygems_version: 2.5.1
110
+ rubygems_version: 2.7.6
88
111
  signing_key:
89
112
  specification_version: 4
90
113
  summary: Deprecation support for your project.
data/CHANGELOG.md DELETED
@@ -1,27 +0,0 @@
1
- ## deprecations 2.0.3
2
- - Ruby 2.3.0 compatibility
3
-
4
- ## deprecations 2.0.2
5
- - add MIT license
6
-
7
- ## deprecations 2.0.1
8
- - little code improvement
9
-
10
- ### deprecations 2.0.0
11
- - supports custom behavior
12
- - supports temporary behavior change
13
- - supports inheritance of deprecated methods
14
- - `Deprecations#configure` and `Deprecations#configuration` are obsolete (use `Deprecations#behavior`)
15
-
16
- ### deprecations 1.0.6
17
- - support for textual alternative of deprecated methods
18
-
19
- ### deprecations 1.0.4
20
- - less code, better algorithm to overload deprecated methods
21
- - no more private «shadow methods»
22
-
23
- ### deprecations 1.0.2
24
- - support for late bound class names (like in `Foo = Class.new`)
25
-
26
- ### deprecations 1.0.0
27
- - initial release
data/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2015 Mike Blumtritt
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 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,
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 THE
21
- SOFTWARE.