deprecation_rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,22 @@
1
+ # Ignore bundler config.
2
+ /.bundle
3
+
4
+ # Ignore all logfiles and tempfiles.
5
+ /log/*.log
6
+ /tmp
7
+
8
+ # OS generated files.
9
+ .DS_Store*
10
+ ehthumbs.db
11
+ Icon?
12
+ Thumbs.db
13
+
14
+ # VIM.
15
+ .*.sw[a-z]
16
+ *.un~
17
+ Session.vim
18
+
19
+ # Yard
20
+ .yardoc
21
+ _yardoc
22
+ doc/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --debug
@@ -0,0 +1,5 @@
1
+ ---
2
+ language: ruby
3
+ rvm:
4
+ - 1.9.2
5
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,112 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ deprecation_rails (0.0.0)
5
+ rails (>= 3.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ actionmailer (3.2.11)
11
+ actionpack (= 3.2.11)
12
+ mail (~> 2.4.4)
13
+ actionpack (3.2.11)
14
+ activemodel (= 3.2.11)
15
+ activesupport (= 3.2.11)
16
+ builder (~> 3.0.0)
17
+ erubis (~> 2.7.0)
18
+ journey (~> 1.0.4)
19
+ rack (~> 1.4.0)
20
+ rack-cache (~> 1.2)
21
+ rack-test (~> 0.6.1)
22
+ sprockets (~> 2.2.1)
23
+ activemodel (3.2.11)
24
+ activesupport (= 3.2.11)
25
+ builder (~> 3.0.0)
26
+ activerecord (3.2.11)
27
+ activemodel (= 3.2.11)
28
+ activesupport (= 3.2.11)
29
+ arel (~> 3.0.2)
30
+ tzinfo (~> 0.3.29)
31
+ activeresource (3.2.11)
32
+ activemodel (= 3.2.11)
33
+ activesupport (= 3.2.11)
34
+ activesupport (3.2.11)
35
+ i18n (~> 0.6)
36
+ multi_json (~> 1.0)
37
+ arel (3.0.2)
38
+ builder (3.0.4)
39
+ columnize (0.3.6)
40
+ debugger (1.2.3)
41
+ columnize (>= 0.3.1)
42
+ debugger-linecache (~> 1.1.1)
43
+ debugger-ruby_core_source (~> 1.1.5)
44
+ debugger-linecache (1.1.2)
45
+ debugger-ruby_core_source (>= 1.1.1)
46
+ debugger-ruby_core_source (1.1.6)
47
+ diff-lcs (1.1.3)
48
+ erubis (2.7.0)
49
+ hike (1.2.1)
50
+ i18n (0.6.1)
51
+ journey (1.0.4)
52
+ json (1.7.6)
53
+ mail (2.4.4)
54
+ i18n (>= 0.4.0)
55
+ mime-types (~> 1.16)
56
+ treetop (~> 1.4.8)
57
+ mime-types (1.19)
58
+ multi_json (1.5.0)
59
+ polyglot (0.3.3)
60
+ rack (1.4.3)
61
+ rack-cache (1.2)
62
+ rack (>= 0.4)
63
+ rack-ssl (1.3.2)
64
+ rack
65
+ rack-test (0.6.2)
66
+ rack (>= 1.0)
67
+ rails (3.2.11)
68
+ actionmailer (= 3.2.11)
69
+ actionpack (= 3.2.11)
70
+ activerecord (= 3.2.11)
71
+ activeresource (= 3.2.11)
72
+ activesupport (= 3.2.11)
73
+ bundler (~> 1.0)
74
+ railties (= 3.2.11)
75
+ railties (3.2.11)
76
+ actionpack (= 3.2.11)
77
+ activesupport (= 3.2.11)
78
+ rack-ssl (~> 1.3.2)
79
+ rake (>= 0.8.7)
80
+ rdoc (~> 3.4)
81
+ thor (>= 0.14.6, < 2.0)
82
+ rake (10.0.3)
83
+ rdoc (3.12)
84
+ json (~> 1.4)
85
+ rspec (2.12.0)
86
+ rspec-core (~> 2.12.0)
87
+ rspec-expectations (~> 2.12.0)
88
+ rspec-mocks (~> 2.12.0)
89
+ rspec-core (2.12.0)
90
+ rspec-expectations (2.12.0)
91
+ diff-lcs (~> 1.1.3)
92
+ rspec-mocks (2.12.0)
93
+ sprockets (2.2.2)
94
+ hike (~> 1.2)
95
+ multi_json (~> 1.0)
96
+ rack (~> 1.0)
97
+ tilt (~> 1.1, != 1.3.0)
98
+ thor (0.16.0)
99
+ tilt (1.3.3)
100
+ treetop (1.4.12)
101
+ polyglot
102
+ polyglot (>= 0.3.1)
103
+ tzinfo (0.3.35)
104
+
105
+ PLATFORMS
106
+ ruby
107
+
108
+ DEPENDENCIES
109
+ debugger (~> 1.2.2)
110
+ deprecation_rails!
111
+ rake
112
+ rspec (~> 2.12.0)
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Jey Balachandran
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,47 @@
1
+ # deprecation_rails [![Build Status](https://travis-ci.org/jeyb/deprecation_rails.png)](https://travis-ci.org/jeyb/deprecation_rails)
2
+ Deprecation policies for your Rails application.
3
+
4
+ ## Usage
5
+ Deprecations can occur on classes or methods.
6
+
7
+ ### Deprecating classes
8
+ ```ruby
9
+ class Array
10
+ include Deprecation::Notifier # Rails controllers and models will have this included by default.
11
+ deprecate at: Date.parse("2013-01-12"), message: "Use BetterArray instead."
12
+ end
13
+ ```
14
+
15
+ This will output:
16
+ ```
17
+ DEPRECATION WARNING: Array is deprecated as of 2013-01-12 00:00:00 -0800. Use BetterArray instead. (called from block (2 levels) in <top (required)> at /../array.rb:11)
18
+ ```
19
+
20
+ ### Deprecating methods
21
+ ```ruby
22
+ class Array
23
+ include Deprecation::Notifier # Rails controllers and models will have this included by default.
24
+
25
+ def id
26
+ object_id
27
+ end
28
+ deprecate :id, at: Date.parse("2013-01-12"), message: "Use object_id instead."
29
+ end
30
+ ```
31
+
32
+ This will output:
33
+ ```
34
+ DEPRECATION WARNING: Array#id is deprecated as of 2013-01-12 00:00:00 -0800. Use object_id instead. (called from block (2 levels) in <top (required)> at /../array.rb:4)
35
+ ```
36
+
37
+ ## Contributing to deprecation_rails
38
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
39
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
40
+ * Fork the project.
41
+ * Start a feature/bugfix branch.
42
+ * Commit and push until you are happy with your contribution.
43
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
44
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
45
+
46
+ ## Copyright
47
+ Copyright (c) 2013 Jey Balachandran. See LICENSE for further details.
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+
3
+ require "rubygems"
4
+ require "bundler/setup"
5
+ require "rake"
6
+
7
+ begin
8
+ Bundler.setup(:default, :development)
9
+ rescue Bundler::BundlerError => exception
10
+ $stderr.puts exception.message
11
+ $stderr.puts "Run `bundle install` to install missing gems"
12
+ exit exception.status_code
13
+ end
14
+
15
+ require "rspec/core"
16
+ require "rspec/core/rake_task"
17
+ RSpec::Core::RakeTask.new(:spec) do |spec|
18
+ spec.pattern = FileList["spec/**/*_spec.rb"]
19
+ end
20
+
21
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
22
+ spec.pattern = "spec/**/*_spec.rb"
23
+ end
24
+
25
+ task default: :spec
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+
3
+ lib = File.expand_path("../lib", __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "deprecation_rails"
8
+ gem.version = "0.0.1"
9
+ gem.authors = ["Jey Balachandran"]
10
+ gem.email = ["jey.balachandran@gmail.com"]
11
+ gem.summary = %q{Deprecation policies for your Rails application.}
12
+ gem.description = %q{Deprecation policies for your Rails application.}
13
+ gem.homepage = "http://github.com/jeyb/deprecation_rails"
14
+ gem.license = "MIT"
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.require_paths = ["lib"]
18
+
19
+ gem.required_ruby_version = ">= 1.9.2"
20
+
21
+ gem.add_dependency "rails", ">= 3.0"
22
+
23
+ gem.add_development_dependency "debugger", "~> 1.2.2"
24
+ gem.add_development_dependency "rake"
25
+ gem.add_development_dependency "rspec", "~> 2.12.0"
26
+ end
@@ -0,0 +1,6 @@
1
+ require "deprecation/version"
2
+ require "deprecation/notifier"
3
+ require "deprecation/engine" if defined?(Rails)
4
+
5
+ module Deprecation
6
+ end
@@ -0,0 +1,15 @@
1
+ module Deprecation
2
+ class Engine < ::Rails::Engine
3
+ initializer "deprecation.initialize" do |app|
4
+ require "deprecation"
5
+
6
+ ActiveSupport.on_load :action_controller do
7
+ ActionController::Base.send :include, Deprecation::Notifier
8
+ end
9
+
10
+ ActiveSupport.on_load(:active_record) do
11
+ ActiveRecord::Base.send :include, Deprecation::Notifier
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,47 @@
1
+ module Deprecation
2
+ module Notifier
3
+ extend ActiveSupport::Concern
4
+
5
+ class << self
6
+ def __deprecation_logger__(class_name, method_name, options = {})
7
+ options = options.symbolize_keys
8
+
9
+ if options[:at].nil? || options[:at].to_time <= Time.now
10
+ message = class_name
11
+ message << "#" << method_name if method_name
12
+ message << " is deprecated"
13
+ message << (options[:at].present?? " as of #{options[:at]}." : ".")
14
+ message << " " << options[:message] if options[:message]
15
+
16
+ ActiveSupport::Deprecation.warn(message, caller[1..-1])
17
+ end
18
+ end
19
+ end
20
+
21
+ module ClassMethods
22
+ def deprecate(*args)
23
+ return if defined?(Rails) && Rails.env.production?
24
+
25
+ if args.size == 0 || args.first.is_a?(Hash)
26
+ deprecate_class(*args)
27
+ else
28
+ deprecate_method(*args)
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def deprecate_class(options = {})
35
+ Deprecation::Notifier.__deprecation_logger__(self.class.name, nil, options)
36
+ end
37
+
38
+ def deprecate_method(method_name, options = {})
39
+ method = instance_method(method_name)
40
+ define_method(method_name) do |*args, &block|
41
+ Deprecation::Notifier.__deprecation_logger__(self.class.name, method_name.to_s, options)
42
+ method.bind(self).(*args, &block)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module Deprecation
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,84 @@
1
+ require "spec_helper"
2
+
3
+ class DeprecatedMethodsTest
4
+ include Deprecation::Notifier
5
+ DAY = 24 * 60 * 60
6
+
7
+ def deprecated_method
8
+ end
9
+ deprecate :deprecated_method
10
+
11
+ def deprecated_method_with_custom_message
12
+ end
13
+ deprecate :deprecated_method_with_custom_message, message: "That Shit Cray"
14
+
15
+ def deprecated_method_as_of_yesterday
16
+ end
17
+ deprecate :deprecated_method_as_of_yesterday, at: Time.now - DAY
18
+
19
+ def deprecated_method_starting_tomorrow
20
+ end
21
+ deprecate :deprecated_method_starting_tomorrow, at: Time.now + DAY
22
+
23
+ def undeprecated_method
24
+ end
25
+ end
26
+
27
+ describe Deprecation do
28
+ subject { DeprecatedMethodsTest.new }
29
+
30
+ it "calls the deprecation logger when the method is deprecated" do
31
+ ActiveSupport::Deprecation.should_receive(:warn)
32
+ subject.deprecated_method
33
+ end
34
+
35
+ it "calls the deprecation logger when the method is deprecated with a custom message" do
36
+ ActiveSupport::Deprecation.should_receive(:warn)
37
+ subject.deprecated_method_with_custom_message
38
+ end
39
+
40
+ it "calls the deprecation logger for methods deprecated as of yesterday" do
41
+ ActiveSupport::Deprecation.should_receive(:warn)
42
+ subject.deprecated_method_as_of_yesterday
43
+ end
44
+
45
+ it "doesn't call the deprecation logger when the method isn't deprecated" do
46
+ ActiveSupport::Deprecation.should_not_receive(:warn)
47
+ subject.undeprecated_method
48
+ end
49
+
50
+ it "doesn't call the deprecation logger for methods deprecated starting tomorrow" do
51
+ ActiveSupport::Deprecation.should_not_receive(:warn)
52
+ subject.deprecated_method_starting_tomorrow
53
+ end
54
+
55
+ it "calls the deprecation logger when the class is defined" do
56
+ ActiveSupport::Deprecation.should_receive(:warn).once
57
+
58
+ class DeprecatedClassTest
59
+ include Deprecation::Notifier
60
+ deprecate
61
+
62
+ def undeprecated_method
63
+ end
64
+ end
65
+
66
+ subject = DeprecatedClassTest.new
67
+ subject.undeprecated_method
68
+ end
69
+
70
+ it "doesn't call the deprecation logger when the class is defined for class deprecated starting tomorrow" do
71
+ ActiveSupport::Deprecation.should_not_receive(:warn)
72
+
73
+ class DeprecatedClassTest
74
+ include Deprecation::Notifier
75
+ deprecate at: Time.now + DeprecatedMethodsTest::DAY
76
+
77
+ def undeprecated_method
78
+ end
79
+ end
80
+
81
+ subject = DeprecatedClassTest.new
82
+ subject.undeprecated_method
83
+ end
84
+ end
@@ -0,0 +1,8 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require "rails/all"
4
+ require "deprecation"
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: deprecation_rails
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Jey Balachandran
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ prerelease: false
16
+ type: :runtime
17
+ version_requirements: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '3.0'
23
+ name: rails
24
+ requirement: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - !ruby/object:Gem::Dependency
31
+ prerelease: false
32
+ type: :development
33
+ version_requirements: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: 1.2.2
39
+ name: debugger
40
+ requirement: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.2.2
46
+ - !ruby/object:Gem::Dependency
47
+ prerelease: false
48
+ type: :development
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ name: rake
56
+ requirement: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ prerelease: false
64
+ type: :development
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ version: 2.12.0
71
+ name: rspec
72
+ requirement: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 2.12.0
78
+ description: Deprecation policies for your Rails application.
79
+ email:
80
+ - jey.balachandran@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - .rspec
87
+ - .travis.yml
88
+ - Gemfile
89
+ - Gemfile.lock
90
+ - LICENSE
91
+ - README.md
92
+ - Rakefile
93
+ - deprecation_rails.gemspec
94
+ - lib/deprecation.rb
95
+ - lib/deprecation/engine.rb
96
+ - lib/deprecation/notifier.rb
97
+ - lib/deprecation/version.rb
98
+ - spec/lib/deprecation_spec.rb
99
+ - spec/spec_helper.rb
100
+ homepage: http://github.com/jeyb/deprecation_rails
101
+ licenses:
102
+ - MIT
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: 1.9.2
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 1.8.24
122
+ signing_key:
123
+ specification_version: 3
124
+ summary: Deprecation policies for your Rails application.
125
+ test_files:
126
+ - spec/lib/deprecation_spec.rb
127
+ - spec/spec_helper.rb
128
+ has_rdoc: