uv_refactor 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source :rubygems
2
+
3
+ gem "activesupport", "~> 3.0.0"
4
+ gem "i18n"
5
+
6
+ group :test, :development do
7
+ gem "rspec"
8
+ gem "autotest"
9
+ gem "autotest-fsevent" if RUBY_PLATFORM =~ /darwin/
10
+ gem "ruby-debug19"
11
+ gem "mocha"
12
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,47 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (3.0.3)
5
+ archive-tar-minitar (0.5.2)
6
+ autotest (4.4.4)
7
+ autotest-fsevent (0.2.3)
8
+ sys-uname
9
+ columnize (0.3.2)
10
+ diff-lcs (1.1.2)
11
+ i18n (0.4.2)
12
+ linecache19 (0.5.11)
13
+ ruby_core_source (>= 0.1.4)
14
+ mocha (0.9.9)
15
+ rake
16
+ rake (0.8.7)
17
+ rspec (2.1.0)
18
+ rspec-core (~> 2.1.0)
19
+ rspec-expectations (~> 2.1.0)
20
+ rspec-mocks (~> 2.1.0)
21
+ rspec-core (2.1.0)
22
+ rspec-expectations (2.1.0)
23
+ diff-lcs (~> 1.1.2)
24
+ rspec-mocks (2.1.0)
25
+ ruby-debug-base19 (0.11.24)
26
+ columnize (>= 0.3.1)
27
+ linecache19 (>= 0.5.11)
28
+ ruby_core_source (>= 0.1.4)
29
+ ruby-debug19 (0.11.6)
30
+ columnize (>= 0.3.1)
31
+ linecache19 (>= 0.5.11)
32
+ ruby-debug-base19 (>= 0.11.19)
33
+ ruby_core_source (0.1.4)
34
+ archive-tar-minitar (>= 0.5.2)
35
+ sys-uname (0.8.4)
36
+
37
+ PLATFORMS
38
+ ruby
39
+
40
+ DEPENDENCIES
41
+ activesupport (~> 3.0.0)
42
+ autotest
43
+ autotest-fsevent
44
+ i18n
45
+ mocha
46
+ rspec
47
+ ruby-debug19
data/README.markdown ADDED
@@ -0,0 +1,78 @@
1
+ # UV Refactor
2
+
3
+ A mixin class which defines some methods to help you refactor your codebase.
4
+
5
+ ## Description
6
+
7
+ If you want to rename methods or relations, it helps to get some reminders that a refactoring is in progress.
8
+ Having methods which hold `refactor`, it becomes easier to spot those methods in your codebase.
9
+
10
+ ## Installation
11
+
12
+ Standalone:
13
+
14
+ gem install uv_refactor
15
+
16
+ With bundler:
17
+
18
+ gem "uv_refactor"
19
+
20
+ ## Usage
21
+
22
+ You have to include the Refactor module. Here is a silly example:
23
+ Imagine you'd like to rename
24
+
25
+ class User < ActiveRecord::Base
26
+ include Refactor
27
+
28
+ refactor_method :fullname, :name
29
+ end
30
+
31
+ ### Refactor methods
32
+
33
+ Creates an attribute accessor for `:new_method` and redirects `:old_method` to it.
34
+
35
+ refactor_method old_method, new_method
36
+
37
+ ## Configure the Refactorer
38
+
39
+ You are able to override the deprecation_method to fit your needs.
40
+
41
+ # config/initializers/currency_updater.rb
42
+
43
+ Refactor.setup do |config|
44
+ config.deprecation_method = lambda {|old_method, new_method| 1.2345 }
45
+ end
46
+
47
+ ## Changelog
48
+
49
+ * 2010-11-21: Project created (0.0.1)
50
+
51
+ ## Contributors
52
+
53
+ * Jan Riethmayer (@riethmayer, maintainer)
54
+
55
+ ## LICENSE
56
+
57
+ (The MIT License)
58
+
59
+ Copyright (c) 2010 [urbanvention](http://urbanvention.com).
60
+
61
+ Permission is hereby granted, free of charge, to any person obtaining
62
+ a copy of this software and associated documentation files (the
63
+ 'Software'), to deal in the Software without restriction, including
64
+ without limitation the rights to use, copy, modify, merge, publish,
65
+ distribute, sublicense, and/or sell copies of the Software, and to
66
+ permit persons to whom the Software is furnished to do so, subject to
67
+ the following conditions:
68
+
69
+ The above copyright notice and this permission notice shall be
70
+ included in all copies or substantial portions of the Software.
71
+
72
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
73
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
74
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
75
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
76
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
77
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
78
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1 @@
1
+ Autotest.add_discovery { "rspec2" }
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'uv_refactor'
@@ -0,0 +1,37 @@
1
+ module Refactor
2
+
3
+ autoload :Deprecation, 'uv_refactor/deprecation'
4
+
5
+ mattr_accessor :deprecation_method
6
+ @@deprecation_method = lambda {|old_method, new_method, klass|
7
+ if klass.instance_methods.include?(old_method)
8
+ Deprecation.remove_old_method(old_method,
9
+ klass,
10
+ eval("caller(0)", &lambda{}))
11
+ end
12
+
13
+ unless klass.instance_methods.include?(new_method)
14
+ Deprecation.missing_database_entry(new_method,klass)
15
+ define_method(new_method) do
16
+ self.class_eval { attr_accessor new_method }
17
+ end
18
+ end
19
+
20
+ define_method(old_method) do |*args, &block|
21
+ Deprecation.
22
+ renaming_warning(old_method,
23
+ new_method,
24
+ # 3rd stacktrace element from caller
25
+ eval("caller(0)", &lambda {}))
26
+ send(new_method, *args, &block)
27
+ end
28
+ }
29
+
30
+ def self.setup
31
+ yield self
32
+ end
33
+
34
+ def self.included(base)
35
+ base.send(:include, Deprecation)
36
+ end
37
+ end
@@ -0,0 +1,55 @@
1
+ module Refactor
2
+ module Deprecation
3
+
4
+ def self.included(base)
5
+ base.send(:extend, ClassMethods)
6
+ base.send(:include, Deprecation::InstanceMethods)
7
+ end
8
+
9
+ module ClassMethods
10
+ def refactor_method(old_method,new_method)
11
+ Refactor.deprecation_method.call(old_method,new_method, self)
12
+ end
13
+ end
14
+
15
+ module InstanceMethods
16
+ def refactor_warnings
17
+ Deprecation::Warnings
18
+ end
19
+ end
20
+
21
+ #----------------------------------------------------------------#
22
+ # Warnings
23
+ #----------------------------------------------------------------#
24
+ Warnings = []
25
+ class << self
26
+ def missing_database_entry new_method, klass
27
+ refactor_warning "Missing migration for #{klass} **#{new_method}**."
28
+ end
29
+
30
+ def renaming_warning(old_method,new_method,origin)
31
+ whereabout = prettify(origin)
32
+ refactor_warning "Remove **#{old_method}** with **#{new_method}** in #{whereabout}."
33
+ end
34
+
35
+ def remove_old_method(old_method,klass,origin)
36
+ whereabout = prettify(origin)
37
+ refactor_warning "Remove **#{old_method}** in #{klass}."
38
+ end
39
+
40
+ def refactor_warning(warning)
41
+ # if defined?(logger)
42
+ # logger.warn warning
43
+ # else
44
+ Warnings << warning
45
+ warn warning
46
+ # end
47
+ end
48
+
49
+ def prettify(origin)
50
+ stack_trace_line = origin[3]
51
+ only_file_and_filenumber = stack_trace_line.gsub(/:in.*$/,"")
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,26 @@
1
+ require "rubygems"
2
+ require "rspec"
3
+
4
+ gem "activesupport"
5
+
6
+ require 'active_support/concern'
7
+ require 'active_support/core_ext/class/attribute_accessors'
8
+ require 'active_support/core_ext/load_error'
9
+ require 'active_support/core_ext/module/attr_internal'
10
+ require 'active_support/core_ext/module/delegation'
11
+ require 'active_support/core_ext/name_error'
12
+ require 'active_support/inflector'
13
+
14
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib', 'uv_refactor')
15
+ require "uv_refactor"
16
+
17
+ begin
18
+ require 'ruby-debug'
19
+ rescue LoadError
20
+ end
21
+
22
+ Dir["#{File.dirname(__FILE__)}/support/*.rb"].each { |f| require f }
23
+
24
+ RSpec.configure do |config|
25
+ config.mock_with :mocha
26
+ end
@@ -0,0 +1,57 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
2
+
3
+ module Refactor
4
+ describe Deprecation do
5
+ class User
6
+ include Refactor
7
+ attr_accessor :foo
8
+
9
+ refactor_method :old_method, :new_method
10
+ refactor_method :old_foo, :foo
11
+
12
+ def existing_method
13
+ "this exists"
14
+ end
15
+
16
+ refactor_method :existing_method, :future_method
17
+ end
18
+
19
+ def migration_warning(method)
20
+ /Missing migration for Refactor::User \*\*#{method}\*\*/
21
+ end
22
+
23
+
24
+ before :each do
25
+ @user = User.new
26
+ end
27
+
28
+ it "should respond to old_method" do
29
+ @user.should respond_to(:old_method)
30
+ end
31
+
32
+ it "should add missing migration warning for new_method" do
33
+ @user.refactor_warnings.join(" ").should match(migration_warning("new_method"))
34
+ end
35
+
36
+ it "should respond_to new_method" do
37
+ @user.should respond_to(:new_method)
38
+ end
39
+
40
+ it "should respond_to old_foo" do
41
+ @user.should respond_to(:old_foo)
42
+ end
43
+
44
+ it "should not warn about a missing migration for foo" do
45
+ @user.refactor_warnings.join(" ").should_not match(migration_warning("foo"))
46
+ end
47
+
48
+ it "should hint if old method exists and you're refactoring" do
49
+ @user.refactor_warnings.join(" ").should match(/Remove \*\*existing_method\*\*/)
50
+ end
51
+
52
+ it "should warn about old methods" do
53
+ @user.old_foo
54
+ @user.refactor_warnings.join(" ").should match(/deprecation_spec.rb/)
55
+ end
56
+ end
57
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uv_refactor
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Jan Riethmayer
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-11-21 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: activesupport
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 3
30
+ - 0
31
+ - 3
32
+ version: 3.0.3
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: i18n
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ segments:
44
+ - 0
45
+ - 4
46
+ - 2
47
+ version: 0.4.2
48
+ type: :runtime
49
+ version_requirements: *id002
50
+ description: Some refactoring helpers.
51
+ email: jan@urbanvention.com
52
+ executables: []
53
+
54
+ extensions: []
55
+
56
+ extra_rdoc_files: []
57
+
58
+ files:
59
+ - Gemfile
60
+ - Gemfile.lock
61
+ - README.markdown
62
+ - init.rb
63
+ - lib/uv_refactor.rb
64
+ - lib/uv_refactor/deprecation.rb
65
+ - autotest/discover.rb
66
+ - spec/spec_helper.rb
67
+ - spec/uv_refactor/deprecation_spec.rb
68
+ has_rdoc: true
69
+ homepage: http://github.com/urbanvention/uv_refactor
70
+ licenses: []
71
+
72
+ post_install_message:
73
+ rdoc_options: []
74
+
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ segments:
83
+ - 1
84
+ - 8
85
+ - 7
86
+ version: 1.8.7
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ segments:
93
+ - 0
94
+ version: "0"
95
+ requirements: []
96
+
97
+ rubyforge_project:
98
+ rubygems_version: 1.3.7
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: Refactoring your rails application.
102
+ test_files:
103
+ - autotest/discover.rb
104
+ - spec/spec_helper.rb
105
+ - spec/uv_refactor/deprecation_spec.rb