rails_refactor 1.1 → 1.2
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.
- data/CHANGELOG +1 -0
- data/README +4 -0
- data/lib/rails_refactor.rb +28 -20
- data/rails_refactor.gemspec +9 -10
- metadata +21 -29
data/CHANGELOG
CHANGED
data/README
CHANGED
@@ -41,3 +41,7 @@ More refactorings coming soon... Please fork and contribute :-)
|
|
41
41
|
|
42
42
|
Started by James Crisp & Ryan Bigg pairing at RORO hack night 24 Nov 2010.
|
43
43
|
Thanks to Andrew Snow for help with Gemification.
|
44
|
+
|
45
|
+
Thanks to Tricon for some improvements and start on TextMate Bundle:
|
46
|
+
https://github.com/Tricon/rails-refactor.tmbundle
|
47
|
+
|
data/lib/rails_refactor.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
require 'active_support/inflector'
|
3
|
+
require 'active_support/core_ext/string/inflections'
|
2
4
|
|
3
5
|
begin
|
4
|
-
|
6
|
+
File.exist? './config/environment.rb'
|
5
7
|
rescue LoadError
|
6
8
|
puts "*** rails_refactor needs to be run from the root of a Rails 3 webapp ***"
|
7
9
|
exit
|
@@ -40,16 +42,22 @@ class Renamer
|
|
40
42
|
`mv app/controllers/#{@from.underscore}.rb #{to_controller_path}`
|
41
43
|
replace_in_file(to_controller_path, @from, @to)
|
42
44
|
|
43
|
-
|
44
|
-
|
45
|
-
|
45
|
+
# TODO: Use cross-platform move commands.
|
46
|
+
if File.exist?("spec/controllers/#{@from.underscore}_spec.rb")
|
47
|
+
to_spec = "spec/controllers/#{to_resource_path}_controller_spec.rb"
|
48
|
+
`mv spec/controllers/#{@from.underscore}_spec.rb #{to_spec}`
|
49
|
+
replace_in_file(to_spec, @from, @to)
|
50
|
+
end
|
46
51
|
|
47
|
-
|
52
|
+
if Dir.exist?("app/views/#{@from_resource_path}")
|
53
|
+
`mv app/views/#{@from_resource_path} app/views/#{to_resource_path}`
|
54
|
+
end
|
48
55
|
|
49
56
|
to_helper_path = "app/helpers/#{to_resource_path}_helper.rb"
|
50
|
-
|
51
|
-
|
52
|
-
|
57
|
+
if File.exist?("app/helpers/#{@from_resource_path}_helper.rb")
|
58
|
+
`mv app/helpers/#{@from_resource_path}_helper.rb #{to_helper_path}`
|
59
|
+
replace_in_file(to_helper_path, @from_resource_name, to_resource_name)
|
60
|
+
end
|
53
61
|
|
54
62
|
replace_in_file('config/routes.rb', @from_resource_path, to_resource_path)
|
55
63
|
end
|
@@ -58,7 +66,7 @@ class Renamer
|
|
58
66
|
setup_for_controller_rename
|
59
67
|
controller_path = "app/controllers/#{@from_controller.underscore}.rb"
|
60
68
|
replace_in_file(controller_path, @from_action, @to)
|
61
|
-
|
69
|
+
|
62
70
|
views_for_action = "app/views/#{@from_resource_path}/#{@from_action}.*"
|
63
71
|
|
64
72
|
Dir[views_for_action].each do |file|
|
@@ -88,7 +96,7 @@ if ARGV.length == 3
|
|
88
96
|
if command == "rename"
|
89
97
|
if from.include? "Controller"
|
90
98
|
if from.include? '.'
|
91
|
-
renamer.controller_action_rename
|
99
|
+
renamer.controller_action_rename
|
92
100
|
else
|
93
101
|
renamer.controller_rename
|
94
102
|
end
|
@@ -116,8 +124,8 @@ elsif ARGV[0] == "test"
|
|
116
124
|
|
117
125
|
def assert_file_changed(path, from, to)
|
118
126
|
contents = File.read(path)
|
119
|
-
assert contents.include?(to)
|
120
|
-
assert !contents.include?(from)
|
127
|
+
assert contents.include?(to)
|
128
|
+
assert !contents.include?(from)
|
121
129
|
end
|
122
130
|
|
123
131
|
def test_model_rename
|
@@ -125,12 +133,12 @@ elsif ARGV[0] == "test"
|
|
125
133
|
|
126
134
|
assert File.exist?("app/models/new_model.rb")
|
127
135
|
assert !File.exist?("app/models/dummy_model.rb")
|
128
|
-
assert_file_changed("app/models/new_model.rb",
|
136
|
+
assert_file_changed("app/models/new_model.rb",
|
129
137
|
"DummyModel", "NewModel")
|
130
138
|
|
131
139
|
assert File.exist?("spec/models/new_model_spec.rb")
|
132
140
|
assert !File.exist?("spec/models/dummy_model_spec.rb")
|
133
|
-
assert_file_changed("spec/models/new_model_spec.rb",
|
141
|
+
assert_file_changed("spec/models/new_model_spec.rb",
|
134
142
|
"DummyModel", "NewModel")
|
135
143
|
|
136
144
|
assert File.exist?("db/migrate/20101230081247_create_new_models.rb")
|
@@ -156,20 +164,20 @@ elsif ARGV[0] == "test"
|
|
156
164
|
assert File.exist?("app/views/hello_world/index.html.erb")
|
157
165
|
assert !File.exist?("app/views/dummies/index.html.erb")
|
158
166
|
|
159
|
-
assert_file_changed("app/controllers/hello_world_controller.rb",
|
167
|
+
assert_file_changed("app/controllers/hello_world_controller.rb",
|
160
168
|
"DummiesController", "HelloWorldController")
|
161
169
|
|
162
170
|
routes_contents = File.read("config/routes.rb")
|
163
|
-
assert routes_contents.include?("hello_world")
|
164
|
-
assert !routes_contents.include?("dummies")
|
171
|
+
assert routes_contents.include?("hello_world")
|
172
|
+
assert !routes_contents.include?("dummies")
|
165
173
|
|
166
174
|
helper_contents = File.read("app/helpers/hello_world_helper.rb")
|
167
|
-
assert helper_contents.include?("HelloWorldHelper")
|
168
|
-
assert !helper_contents.include?("DummiesHelper")
|
175
|
+
assert helper_contents.include?("HelloWorldHelper")
|
176
|
+
assert !helper_contents.include?("DummiesHelper")
|
169
177
|
|
170
178
|
assert File.exist?("spec/controllers/hello_world_controller_spec.rb")
|
171
179
|
assert !File.exist?("spec/controllers/dummies_controller_spec.rb")
|
172
|
-
assert_file_changed("spec/controllers/hello_world_controller_spec.rb",
|
180
|
+
assert_file_changed("spec/controllers/hello_world_controller_spec.rb",
|
173
181
|
"DummiesController", "HelloWorldController")
|
174
182
|
end
|
175
183
|
end
|
data/rails_refactor.gemspec
CHANGED
@@ -1,24 +1,23 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
|
-
s.name =
|
5
|
-
s.version = "1.
|
4
|
+
s.name = "rails_refactor"
|
5
|
+
s.version = "1.2"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["James Crisp & Ryan Bigg"]
|
9
|
-
s.date =
|
10
|
-
s.
|
11
|
-
s.
|
12
|
-
s.email = %q{james@crispdesign.net}
|
9
|
+
s.date = "2012-07-18"
|
10
|
+
s.description = "Simple refactoring like rename class for Rails projects"
|
11
|
+
s.email = "james@crispdesign.net"
|
13
12
|
s.executables = ["rails_refactor"]
|
14
13
|
s.extra_rdoc_files = ["CHANGELOG", "README", "bin/rails_refactor", "lib/rails_refactor.rb"]
|
15
14
|
s.files = ["CHANGELOG", "Gemfile", "Gemfile.lock", "Manifest", "README", "Rakefile", "bin/rails_refactor", "dummy/Gemfile", "dummy/Gemfile.lock", "dummy/README", "dummy/Rakefile", "dummy/app/controllers/application_controller.rb", "dummy/app/controllers/dummies_controller.rb", "dummy/app/helpers/application_helper.rb", "dummy/app/helpers/dummies_helper.rb", "dummy/app/models/dummy_model.rb", "dummy/app/views/dummies/index.html.erb", "dummy/app/views/layouts/application.html.erb", "dummy/autotest/discover.rb", "dummy/config.ru", "dummy/config/application.rb", "dummy/config/boot.rb", "dummy/config/database.yml", "dummy/config/environment.rb", "dummy/config/environments/development.rb", "dummy/config/environments/production.rb", "dummy/config/environments/test.rb", "dummy/config/initializers/backtrace_silencers.rb", "dummy/config/initializers/inflections.rb", "dummy/config/initializers/mime_types.rb", "dummy/config/initializers/secret_token.rb", "dummy/config/initializers/session_store.rb", "dummy/config/locales/en.yml", "dummy/config/routes.rb", "dummy/db/migrate/20101230081247_create_dummy_models.rb", "dummy/db/seeds.rb", "dummy/doc/README_FOR_APP", "dummy/public/404.html", "dummy/public/422.html", "dummy/public/500.html", "dummy/public/favicon.ico", "dummy/public/images/rails.png", "dummy/public/index.html", "dummy/public/javascripts/application.js", "dummy/public/javascripts/controls.js", "dummy/public/javascripts/dragdrop.js", "dummy/public/javascripts/effects.js", "dummy/public/javascripts/prototype.js", "dummy/public/javascripts/rails.js", "dummy/public/robots.txt", "dummy/script/rails", "dummy/spec/controllers/dummies_controller_spec.rb", "dummy/spec/helpers/dummies_helper_spec.rb", "dummy/spec/models/dummy_model_spec.rb", "dummy/spec/spec_helper.rb", "dummy/test/functional/dummies_controller_test.rb", "dummy/test/performance/browsing_test.rb", "dummy/test/test_helper.rb", "dummy/test/unit/helpers/dummies_helper_test.rb", "lib/rails_refactor.rb", "rails_refactor.gemspec"]
|
16
|
-
s.homepage =
|
15
|
+
s.homepage = "https://github.com/jcrisp/rails_refactor"
|
17
16
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Rails_refactor", "--main", "README"]
|
18
17
|
s.require_paths = ["lib"]
|
19
|
-
s.rubyforge_project =
|
20
|
-
s.rubygems_version =
|
21
|
-
s.summary =
|
18
|
+
s.rubyforge_project = "rails_refactor"
|
19
|
+
s.rubygems_version = "1.8.24"
|
20
|
+
s.summary = "Simple refactoring like rename class for Rails projects"
|
22
21
|
|
23
22
|
if s.respond_to? :specification_version then
|
24
23
|
s.specification_version = 3
|
metadata
CHANGED
@@ -1,31 +1,27 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_refactor
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.2'
|
4
5
|
prerelease:
|
5
|
-
version: "1.1"
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- James Crisp & Ryan Bigg
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
date: 2011-05-04 00:00:00 +10:00
|
14
|
-
default_executable:
|
12
|
+
date: 2012-07-18 00:00:00.000000000 Z
|
15
13
|
dependencies: []
|
16
|
-
|
17
14
|
description: Simple refactoring like rename class for Rails projects
|
18
15
|
email: james@crispdesign.net
|
19
|
-
executables:
|
16
|
+
executables:
|
20
17
|
- rails_refactor
|
21
18
|
extensions: []
|
22
|
-
|
23
|
-
extra_rdoc_files:
|
19
|
+
extra_rdoc_files:
|
24
20
|
- CHANGELOG
|
25
21
|
- README
|
26
22
|
- bin/rails_refactor
|
27
23
|
- lib/rails_refactor.rb
|
28
|
-
files:
|
24
|
+
files:
|
29
25
|
- CHANGELOG
|
30
26
|
- Gemfile
|
31
27
|
- Gemfile.lock
|
@@ -87,38 +83,34 @@ files:
|
|
87
83
|
- dummy/test/unit/helpers/dummies_helper_test.rb
|
88
84
|
- lib/rails_refactor.rb
|
89
85
|
- rails_refactor.gemspec
|
90
|
-
has_rdoc: true
|
91
86
|
homepage: https://github.com/jcrisp/rails_refactor
|
92
87
|
licenses: []
|
93
|
-
|
94
88
|
post_install_message:
|
95
|
-
rdoc_options:
|
89
|
+
rdoc_options:
|
96
90
|
- --line-numbers
|
97
91
|
- --inline-source
|
98
92
|
- --title
|
99
93
|
- Rails_refactor
|
100
94
|
- --main
|
101
95
|
- README
|
102
|
-
require_paths:
|
96
|
+
require_paths:
|
103
97
|
- lib
|
104
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
99
|
none: false
|
106
|
-
requirements:
|
107
|
-
- -
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version:
|
110
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
105
|
none: false
|
112
|
-
requirements:
|
113
|
-
- -
|
114
|
-
- !ruby/object:Gem::Version
|
115
|
-
version:
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '1.2'
|
116
110
|
requirements: []
|
117
|
-
|
118
111
|
rubyforge_project: rails_refactor
|
119
|
-
rubygems_version: 1.
|
112
|
+
rubygems_version: 1.8.24
|
120
113
|
signing_key:
|
121
114
|
specification_version: 3
|
122
115
|
summary: Simple refactoring like rename class for Rails projects
|
123
116
|
test_files: []
|
124
|
-
|