uncruft 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -0
- data/lib/uncruft.rb +1 -0
- data/lib/uncruft/deprecatable.rb +25 -0
- data/lib/uncruft/version.rb +1 -1
- data/spec/uncruft/deprecatable_spec.rb +58 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0574a8f06a56e8a78866055e1a06e190dbd98925c956deaf66c035f20f4fda7b
|
4
|
+
data.tar.gz: c4a7eeeb9cfb6bf8d565a81c798b9688f5307a97ba597187063c2914e054101d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1fe67350e730b54703a2267a3f8513684cc94840d8a81085b081d45a1f73bd9db1e4adb9c6a9e32980815f002ef1f27aa178090c6e4b80713f3cd507a6db52e9
|
7
|
+
data.tar.gz: fd800818c479fdac5e7b286eae6248f19b35a2f75ae8de946a2d850db91c968dc9d6c7a7e0d9049eff1059a990d1244f0035bfb750c2fdc78bfd879aac914960
|
data/README.md
CHANGED
@@ -39,6 +39,29 @@ You can also incrementally add new warnings to the ignorefile as you encounter t
|
|
39
39
|
RECORD_DEPRECATIONS=1 rspec path/to/my/failing/spec.rb
|
40
40
|
```
|
41
41
|
|
42
|
+
## Deprecating Attributes and Methods
|
43
|
+
|
44
|
+
If you would like to deprecate an attribute by applying a `ActiveSupport::Deprecation` warning on the deprecated attribute's getters and setters then look no further, we have a tool for that! Simply include `Uncruft::Deprecatable` in your class, identify the attribute you would like deprecated and provide a message you would like applied to the deprecation warning.
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
class Customer
|
48
|
+
include Uncruft::Deprecatable
|
49
|
+
|
50
|
+
attr_accessor :first_name
|
51
|
+
|
52
|
+
def initialize(first_name)
|
53
|
+
@first_name = first_name
|
54
|
+
end
|
55
|
+
|
56
|
+
deprecate_attribute(:first_name,
|
57
|
+
message: "Please stop using first_name it is deprecated, please use legal_first_name instead!")
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
Within the `Uncruft::Deprecatable` module there is also a `.deprecate_method` method that can be used to apply a deprecation warning to an identified method, much like the `deprecate_attribute` method described above.
|
62
|
+
|
63
|
+
From there you can use Uncruft's deprecation recording tools to generate ingorefiles and manage your deprecation backlog in an organized manner.
|
64
|
+
|
42
65
|
## How to Contribute
|
43
66
|
|
44
67
|
We would love for you to contribute! Anything that benefits the majority of users—from a documentation fix to an entirely new feature—is encouraged.
|
data/lib/uncruft.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
module Uncruft
|
2
|
+
module Deprecatable
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
def deprecate_attribute(attribute, message:)
|
7
|
+
deprecate_method attribute, message: message
|
8
|
+
deprecate_method :"#{attribute}=", message: message
|
9
|
+
end
|
10
|
+
|
11
|
+
def deprecate_method(method, message:)
|
12
|
+
prepended_method = Module.new
|
13
|
+
|
14
|
+
prepended_method.module_eval do
|
15
|
+
define_method method do |*args, &block|
|
16
|
+
ActiveSupport::Deprecation.warn(message)
|
17
|
+
super(*args, &block)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
prepend prepended_method
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/uncruft/version.rb
CHANGED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Uncruft::Deprecatable do
|
4
|
+
let(:my_name) { "Jess" }
|
5
|
+
|
6
|
+
subject { klass.new }
|
7
|
+
|
8
|
+
describe '.deprecate_attribute' do
|
9
|
+
let(:klass) do
|
10
|
+
Class.new do
|
11
|
+
include Uncruft::Deprecatable
|
12
|
+
|
13
|
+
attr_accessor :first_name
|
14
|
+
|
15
|
+
deprecate_attribute(:first_name,
|
16
|
+
message: "Please stop using this attribute!")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'applies deprecation warning when setting deprecated attribute' do
|
21
|
+
expect(ActiveSupport::Deprecation).to receive(:warn).once
|
22
|
+
.with("Please stop using this attribute!")
|
23
|
+
|
24
|
+
expect(subject.first_name = my_name).to eq my_name
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'applies deprecation warning when getting deprecated attribute' do
|
28
|
+
subject.instance_variable_set(:@first_name, my_name)
|
29
|
+
|
30
|
+
expect(ActiveSupport::Deprecation).to receive(:warn)
|
31
|
+
.with("Please stop using this attribute!")
|
32
|
+
|
33
|
+
expect(subject.first_name).to eq my_name
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '.deprecate_method' do
|
38
|
+
let(:klass) do
|
39
|
+
Class.new do
|
40
|
+
include Uncruft::Deprecatable
|
41
|
+
|
42
|
+
def legacy_method
|
43
|
+
"Hello Old World!"
|
44
|
+
end
|
45
|
+
|
46
|
+
deprecate_method(:legacy_method,
|
47
|
+
message: "Please stop using this method!")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'applies deprecation warning when calling the deprecated method' do
|
52
|
+
expect(ActiveSupport::Deprecation).to receive(:warn)
|
53
|
+
.with("Please stop using this method!")
|
54
|
+
|
55
|
+
expect(subject.legacy_method).to eq "Hello Old World!"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uncruft
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Griffith
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-
|
12
|
+
date: 2020-08-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|
@@ -107,6 +107,7 @@ files:
|
|
107
107
|
- README.md
|
108
108
|
- Rakefile
|
109
109
|
- lib/uncruft.rb
|
110
|
+
- lib/uncruft/deprecatable.rb
|
110
111
|
- lib/uncruft/deprecation_handler.rb
|
111
112
|
- lib/uncruft/railtie.rb
|
112
113
|
- lib/uncruft/version.rb
|
@@ -116,6 +117,7 @@ files:
|
|
116
117
|
- spec/examples.txt
|
117
118
|
- spec/spec_helper.rb
|
118
119
|
- spec/support/rails_root.rb
|
120
|
+
- spec/uncruft/deprecatable_spec.rb
|
119
121
|
- spec/uncruft/deprecation_handler_spec.rb
|
120
122
|
- spec/uncruft/railtie_spec.rb
|
121
123
|
- spec/uncruft/warning_spec.rb
|
@@ -150,6 +152,7 @@ test_files:
|
|
150
152
|
- spec/examples.txt
|
151
153
|
- spec/uncruft/railtie_spec.rb
|
152
154
|
- spec/uncruft/warning_spec.rb
|
155
|
+
- spec/uncruft/deprecatable_spec.rb
|
153
156
|
- spec/uncruft/deprecation_handler_spec.rb
|
154
157
|
- spec/support/rails_root.rb
|
155
158
|
- spec/uncruft_spec.rb
|