deprecations 1.0.0 → 1.0.1

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
  SHA1:
3
- metadata.gz: b74900a310d72869dfae2f9b091e9a48da08b5fa
4
- data.tar.gz: fc6eda630d25dbcde15725ace76a8a3d0a539c83
3
+ metadata.gz: 42b4cf87903a557ef44e7fa0f7d8e7cbda134c7f
4
+ data.tar.gz: 23360fbe0f87964cde7e0987c7df5ae10c3cd172
5
5
  SHA512:
6
- metadata.gz: f52526544a564d6be8c33d69f2140131e914adc480a0644578f8655c09b8201e4cdcf1dd43d30cb74aa5f311cce9fb52f1db349bec6874886e305fab1d60ff74
7
- data.tar.gz: 0a7e22ebf74c2c8264f58e12abaa551b8c68d6b6921d03efc643e74dbf77029e27f9dbb28809ce6038bda2c40e6bb1bf1e3a96352b665bc306140307f056378c
6
+ metadata.gz: 64409aa1740a08d1cabe23694cfaf86ca95eb0348ca9f0ff90f5589dc9cbe771d5696f631f1dab038bf0b1c945f1c0524d2322dd086b8f9ab6801207178a49d4
7
+ data.tar.gz: e2b7f0edbbbb9df6f32f10210b02c3cc2c8c3160b8831ba1f15c14a2874c70925b0797741d2597ff7a329fb66f5ef1ceeb4f091e98e6de15cb949efa6c51a275
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  This gem provides transparent declaration of deprecated methods and classes.
4
4
 
5
+ [![Code Climate](https://codeclimate.com/github/mblumtritt/deprecations.png)](https://codeclimate.com/github/mblumtritt/deprecations)
6
+
5
7
  ## Installation
6
8
 
7
9
  The simplest way to install Deprecations gem is to use [Bundler](http://gembundler.com/).
data/lib/deprecations.rb CHANGED
@@ -1,4 +1,6 @@
1
1
 
2
+ DeprecationError = Class.new(ScriptError)
3
+
2
4
  module Deprecations
3
5
  autoload(:VERSION, "#{__FILE__[/.*(?=\..+$)/]}/version")
4
6
  require_relative 'deprecations/configuration'
@@ -17,19 +17,22 @@ module Deprecations
17
17
  nil
18
18
  end
19
19
 
20
- def __define_deprecated(opts)
21
- alias_name = "deprecated_#{opts[:name]}"
22
- private_method_defined?(alias_name) and raise(
23
- ScriptError, "method is already deprecated - #{opts[:decorated]}"
24
- )
25
- alias_method(alias_name, opts[:name])
26
- private(alias_name)
27
- define_method(opts[:name]) do |*a, &b|
28
- Deprecations.call(opts[:decorated], opts[:alternative], opts[:outdated])
20
+ def __define_deprecated(name, decorated_name, scope, alternative, outdated)
21
+ alias_name = __private_alias(name, decorated_name )
22
+ define_method(name) do |*a, &b|
23
+ Deprecations.call(decorated_name, alternative, outdated)
29
24
  send(alias_name, *a, &b)
30
25
  end
31
- send(opts[:scope], opts[:name])
32
- opts[:name]
26
+ send(scope, name)
27
+ name
28
+ end
29
+
30
+ def __private_alias(name, decorated_name)
31
+ alias_name = "deprecated_#{name}"
32
+ private_method_defined?(alias_name) and raise(ScriptError, "method is already deprecated - #{decorated_name}")
33
+ alias_method(alias_name, name)
34
+ private(alias_name)
35
+ alias_name
33
36
  end
34
37
  end
35
38
 
@@ -40,11 +43,11 @@ module Deprecations
40
43
  def deprecated(method_name, alternative_method_name = nil, outdated = nil)
41
44
  method_scope = __method_scope(method_name) or __not_found!(method_name)
42
45
  __define_deprecated(
43
- name: method_name,
44
- scope: method_scope,
45
- decorated: "#{self.inspect[8..-2]}.#{method_name}",
46
- alternative: __decorated(alternative_method_name),
47
- outdated: outdated
46
+ method_name,
47
+ "#{self.inspect[8..-2]}.#{method_name}",
48
+ method_scope,
49
+ __decorated(alternative_method_name),
50
+ outdated
48
51
  )
49
52
  ensure
50
53
  $@ and $@.delete_if{ |s| s.index(__FILE__) }
@@ -69,21 +72,21 @@ module Deprecations
69
72
  def deprecated!(alternative = nil, outdated = nil)
70
73
  singleton_class.send(
71
74
  :__define_deprecated,
72
- name: :new,
73
- scope: :public,
74
- decorated: name,
75
- alternative: alternative ? "#{alternative}" : nil,
76
- outdated: outdated
75
+ :new,
76
+ name,
77
+ :public,
78
+ alternative ? "#{alternative}" : nil,
79
+ outdated
77
80
  )
78
81
  end
79
82
 
80
83
  def deprecated(method_name, alternative_method_name = nil, outdated = nil)
81
84
  method_scope = __method_scope(method_name) and return __define_deprecated(
82
- name: method_name,
83
- scope: method_scope,
84
- decorated: "#{name}##{method_name}",
85
- alternative: __decorated(alternative_method_name),
86
- outdated: outdated
85
+ method_name,
86
+ "#{name}##{method_name}",
87
+ method_scope,
88
+ __decorated(alternative_method_name),
89
+ outdated
87
90
  )
88
91
  singleton_class.send(:deprecated, method_name, alternative_method_name, outdated)
89
92
  ensure
@@ -98,5 +101,4 @@ module Deprecations
98
101
  end
99
102
 
100
103
  infect(Module)
101
- TOPLEVEL_BINDING.eval('DeprecationError = Class.new(ScriptError)')
102
104
  end
@@ -1,3 +1,3 @@
1
1
  module Deprecations
2
- VERSION = '1.0.0'
2
+ VERSION = '1.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: 1.0.0
4
+ version: 1.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: 2014-06-29 00:00:00.000000000 Z
11
+ date: 2014-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake