imprecations 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/Gemfile +4 -0
- data/README.md +28 -0
- data/Rakefile +8 -0
- data/imprecations.gemspec +21 -0
- data/lib/imprecations.rb +55 -0
- data/lib/imprecations/safe.rb +4 -0
- data/lib/imprecations/version.rb +3 -0
- data/spec/imprecations_spec.rb +70 -0
- data/spec/spec_helper.rb +4 -0
- metadata +69 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Imprecations: Because that's what you'll be hurling at the screen
|
2
|
+
|
3
|
+
Imprecations recursively deprecates every instance method on a class/module as
|
4
|
+
well as all classes defined inside that class/module.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
gem install imprecations
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
|
12
|
+
MyClass.imprecate
|
13
|
+
MyClass.my_method
|
14
|
+
#=> DEPRECATION WARNING: MyClass#my_method is deprecated!
|
15
|
+
#=> ...my_method does its thing...
|
16
|
+
|
17
|
+
## Safety
|
18
|
+
Worried about deprecating too many things? Just do this:
|
19
|
+
|
20
|
+
require 'imprecations/safe'
|
21
|
+
|
22
|
+
And you're good to go!
|
23
|
+
|
24
|
+
|
25
|
+
## Is it tested?
|
26
|
+
Of course!
|
27
|
+
|
28
|
+
Author/who to blame: Gabe Berke-Williams, 2011
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "imprecations/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "imprecations"
|
7
|
+
s.version = Imprecations::VERSION
|
8
|
+
s.authors = ["Gabe Berke-Williams"]
|
9
|
+
s.email = ["gabe@thoughtbot.com"]
|
10
|
+
s.homepage = "https://github.com/gabebw/imprecations/"
|
11
|
+
s.summary = %q{Deprecate ALL THE THINGS!}
|
12
|
+
s.description = [%q{Imprecations recursively deprecates every instance method},
|
13
|
+
%q{on a class/module as well as all classes defined inside that class/module.}].join(' ')
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.add_development_dependency('rspec', '~> 2.6.0')
|
21
|
+
end
|
data/lib/imprecations.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require "imprecations/version"
|
2
|
+
|
3
|
+
module Imprecations
|
4
|
+
def imprecate
|
5
|
+
if [Object, Module, Kernel].include?(self)
|
6
|
+
raise "Imprecate *#{self}*?! Sorry, even I'm not that evil."
|
7
|
+
end
|
8
|
+
|
9
|
+
__imprecate(self)
|
10
|
+
self.imprecate_child_constants
|
11
|
+
end
|
12
|
+
|
13
|
+
def imprecate_child_constants
|
14
|
+
real_constants = self.constants.map{|c| self.const_get(c) }
|
15
|
+
class_constants = real_constants.select{|c| Class === c }
|
16
|
+
class_constants.each do |class_const|
|
17
|
+
class_const.imprecate
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def __imprecate(constant)
|
22
|
+
unimprecated_instance_methods_for(constant).each do |meth|
|
23
|
+
namespaced_constant =
|
24
|
+
if self.superclass == Object
|
25
|
+
"#{constant}"
|
26
|
+
else
|
27
|
+
"#{self.superclass}::#{constant}"
|
28
|
+
end
|
29
|
+
|
30
|
+
constant.class_eval <<-EVIL
|
31
|
+
# Store a reference
|
32
|
+
alias :"__unimprecated_#{meth}" :"#{meth}"
|
33
|
+
|
34
|
+
# Undefine it so we can redefine it
|
35
|
+
undef_method(:"#{meth}")
|
36
|
+
|
37
|
+
def #{meth}
|
38
|
+
Imprecations.say("DEPRECATION WARNING: #{namespaced_constant}##{meth} is deprecated!")
|
39
|
+
__unimprecated_#{meth}()
|
40
|
+
end
|
41
|
+
EVIL
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def unimprecated_instance_methods_for(constant)
|
46
|
+
methods = constant.instance_methods(false)
|
47
|
+
methods.reject{|meth| meth.to_s =~ /^__unimprecated/ }
|
48
|
+
end
|
49
|
+
|
50
|
+
def say(message)
|
51
|
+
puts message
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
include Imprecations
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Imprecations, "#imprecate" do
|
4
|
+
before do
|
5
|
+
Object.send(:remove_const, :MyModule) if defined?(MyModule)
|
6
|
+
Object.send(:remove_const, :MyClass) if defined?(MyClass)
|
7
|
+
|
8
|
+
module MyModule; end
|
9
|
+
|
10
|
+
class MyClass
|
11
|
+
class MySubClass
|
12
|
+
def sub_one
|
13
|
+
end
|
14
|
+
|
15
|
+
class MyTripleSubClass
|
16
|
+
def triple_sub
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def one; end
|
22
|
+
def two; end
|
23
|
+
|
24
|
+
def three
|
25
|
+
called_by_three
|
26
|
+
end
|
27
|
+
|
28
|
+
def called_by_three
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it "is available on any Object" do
|
34
|
+
MyClass.should respond_to :imprecate
|
35
|
+
MyClass::MySubClass.should respond_to :imprecate
|
36
|
+
MyModule.should respond_to :imprecate
|
37
|
+
end
|
38
|
+
|
39
|
+
it "adds deprecation warnings for every instance method" do
|
40
|
+
Imprecations.should_receive(:say).with("DEPRECATION WARNING: MyClass#one is deprecated!")
|
41
|
+
Imprecations.should_receive(:say).with("DEPRECATION WARNING: MyClass#two is deprecated!")
|
42
|
+
|
43
|
+
MyClass.imprecate
|
44
|
+
instance = MyClass.new
|
45
|
+
instance.one
|
46
|
+
instance.two
|
47
|
+
end
|
48
|
+
|
49
|
+
it "recursively adds deprecation warnings for every instance method" do
|
50
|
+
Imprecations.should_receive(:say).with("DEPRECATION WARNING: MyClass::MySubClass::MyTripleSubClass#triple_sub is deprecated!")
|
51
|
+
|
52
|
+
MyClass.imprecate
|
53
|
+
MyClass::MySubClass::MyTripleSubClass.new.triple_sub
|
54
|
+
end
|
55
|
+
|
56
|
+
it "calls the original method" do
|
57
|
+
MyClass.any_instance.should_receive(:called_by_three)
|
58
|
+
|
59
|
+
MyClass.imprecate
|
60
|
+
MyClass.new.three
|
61
|
+
end
|
62
|
+
|
63
|
+
[Object, Module, Kernel].each do |important_class|
|
64
|
+
it "refuses to imprecate #{important_class}" do
|
65
|
+
lambda do
|
66
|
+
important_class.imprecate
|
67
|
+
end.should raise_error
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: imprecations
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Gabe Berke-Williams
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-09-08 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &2153095880 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.6.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2153095880
|
25
|
+
description: Imprecations recursively deprecates every instance method on a class/module
|
26
|
+
as well as all classes defined inside that class/module.
|
27
|
+
email:
|
28
|
+
- gabe@thoughtbot.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- .gitignore
|
34
|
+
- Gemfile
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- imprecations.gemspec
|
38
|
+
- lib/imprecations.rb
|
39
|
+
- lib/imprecations/safe.rb
|
40
|
+
- lib/imprecations/version.rb
|
41
|
+
- spec/imprecations_spec.rb
|
42
|
+
- spec/spec_helper.rb
|
43
|
+
homepage: https://github.com/gabebw/imprecations/
|
44
|
+
licenses: []
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 1.8.9
|
64
|
+
signing_key:
|
65
|
+
specification_version: 3
|
66
|
+
summary: Deprecate ALL THE THINGS!
|
67
|
+
test_files:
|
68
|
+
- spec/imprecations_spec.rb
|
69
|
+
- spec/spec_helper.rb
|