wize_upgrader 0.0.5 → 0.0.6
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.
- checksums.yaml +7 -0
- data/lib/wize_upgrader.rb +63 -55
- metadata +7 -10
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4a461e0f49e7da1a6767f07166f0f31ffa42fd91
|
4
|
+
data.tar.gz: da0b5c2aa8e764d754f0a6f8be7a01fbae975144
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ca7b3c4231103939815e1b862e72fc23253cdec38ea7c4ea68ff3f8fbb157b8d505550c2b8e35c0ae8dff9011e58c345711689a16fe6049afa8eb4368b383366
|
7
|
+
data.tar.gz: 51fc50c373f1ce3cade4073105ff2137032a670ed03a45281c26c56a5df7e8023be43d7df685367173a61e64f16f1ff9e28f2db7e0ff8ea69c645926983dc91b
|
data/lib/wize_upgrader.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
require 'fileutils'
|
2
3
|
require 'active_support/inflector'
|
3
|
-
require 'debugger'
|
4
4
|
|
5
5
|
module Wize
|
6
6
|
class Upgrader
|
7
7
|
SOFT_DIR_MAPPINGS = {
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
8
|
+
'.git' => '.git',
|
9
|
+
'.gitignore' => '.gitignore',
|
10
|
+
'script' => 'bin',
|
11
|
+
'db' => 'db',
|
12
|
+
'lib' => 'lib',
|
13
|
+
'spec' => 'spec',
|
14
|
+
'vendor' => 'vendor'
|
15
15
|
}
|
16
16
|
HARD_DIR_MAPPINGS = {
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
'app' => 'app',
|
18
|
+
'config/locales' => 'config/locales',
|
19
|
+
'config/initializers' => 'config/initializers'
|
20
20
|
}
|
21
21
|
COMMON_GEMS = [
|
22
22
|
"gem 'jquery-rails'",
|
@@ -34,10 +34,10 @@ module Wize
|
|
34
34
|
"gem 'rails', '3.2.15'"
|
35
35
|
]
|
36
36
|
COMMON_FILES = [
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
'config/application.yml',
|
38
|
+
'config/database.yml',
|
39
|
+
'config/routes.rb',
|
40
|
+
'README.md'
|
41
41
|
]
|
42
42
|
|
43
43
|
def initialize(old_app_name)
|
@@ -46,8 +46,7 @@ module Wize
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def upgrade
|
49
|
-
puts "-------
|
50
|
-
|
49
|
+
puts "-------UPGRADING #{@new_name} FROM RAILS 3.2 to RAILS 4-------"
|
51
50
|
begin
|
52
51
|
rename_old
|
53
52
|
rails_gen_new
|
@@ -60,10 +59,8 @@ module Wize
|
|
60
59
|
rescue => e
|
61
60
|
puts e.message
|
62
61
|
puts e.backtrace
|
63
|
-
puts "something went wrong!"
|
64
|
-
ensure
|
65
62
|
end
|
66
|
-
puts
|
63
|
+
puts '------ DONE UPGRADING! HAVE FUN ------'
|
67
64
|
end
|
68
65
|
|
69
66
|
def install_rspec
|
@@ -78,52 +75,64 @@ module Wize
|
|
78
75
|
end
|
79
76
|
|
80
77
|
def fix_controllers
|
81
|
-
files_for("#{
|
78
|
+
files_for("#{@new_name}/app/controllers").each { |c| fix_controller(c) }
|
82
79
|
end
|
83
80
|
|
84
|
-
def
|
85
|
-
|
86
|
-
model = File.basename(file).gsub("_controller.rb", "").singularize
|
87
|
-
return if attr_accessibles[model].empty?
|
88
|
-
|
89
|
-
columns = attr_accessibles[model]
|
90
|
-
params_block = <<-rb
|
81
|
+
def params_block(model, columns)
|
82
|
+
<<-rb
|
91
83
|
|
92
84
|
private
|
93
85
|
def #{ model }_params
|
94
|
-
params.require(:#{ model }).permit(#{ columns.join(
|
86
|
+
params.require(:#{ model }).permit(#{ columns.join(', ') })
|
95
87
|
end
|
96
88
|
rb
|
89
|
+
end
|
90
|
+
|
91
|
+
def model_from_file_name(file_name)
|
92
|
+
File.basename(file).gsub('_controller.rb', '').singularize
|
93
|
+
end
|
94
|
+
|
95
|
+
def fix_controller(file)
|
96
|
+
model = model_from_file_name(file)
|
97
|
+
return if attr_accessibles[model].empty?
|
98
|
+
|
99
|
+
puts "fixing #{ file }"
|
100
|
+
columns = attr_accessibles[model]
|
97
101
|
|
98
102
|
# find last occurance of end and replace with params_block
|
99
103
|
ctrlr = File.read("#{ @new_name }/app/controllers/#{ file }")
|
100
|
-
end_idx = ctrlr.rindex(
|
101
|
-
|
102
|
-
ctrlr.insert(end_idx, params_block)
|
104
|
+
end_idx = ctrlr.rindex('end')
|
105
|
+
ctrlr.insert(end_idx, params_block(model, columns))
|
103
106
|
ctrlr.gsub!("params[:#{ model }]", "#{ model }_params")
|
104
107
|
|
105
|
-
File.open("#{ @new_name }/app/controllers/#{ file }.tmp",
|
108
|
+
File.open("#{ @new_name }/app/controllers/#{ file }.tmp", 'w') do |n|
|
106
109
|
n.write(ctrlr)
|
107
110
|
end
|
108
|
-
|
111
|
+
clean_up_tmp(file)
|
112
|
+
end
|
113
|
+
|
114
|
+
def clean_up_tmp(file)
|
115
|
+
from_file = "#{ @new_name }/app/controllers/#{file}.tmp"
|
116
|
+
to_file = "#{ @new_name }/app/controllers/#{file}"
|
117
|
+
`mv #{from_file} #{to_file}`
|
109
118
|
end
|
110
119
|
|
111
120
|
def fix_models
|
112
|
-
puts
|
121
|
+
puts 'pulling out attr_accessible from models'
|
113
122
|
files_for("#{ @new_name }/app/models").each { |m| fix_model(m) }
|
114
123
|
end
|
115
124
|
|
116
125
|
def fix_model(file)
|
117
|
-
lower_model = file.gsub(
|
126
|
+
lower_model = file.gsub('.rb', '')
|
118
127
|
puts "fixing #{ lower_model }"
|
119
|
-
File.open("#{ @new_name }/app/models/#{ file }",
|
120
|
-
File.open("#{ @new_name }/app/models/#{ file }.tmp",
|
128
|
+
File.open("#{ @new_name }/app/models/#{ file }", 'r') do |old|
|
129
|
+
File.open("#{ @new_name }/app/models/#{ file }.tmp", 'w') do |n|
|
121
130
|
old.each_line do |line|
|
122
|
-
if line.strip.start_with?(
|
131
|
+
if line.strip.start_with?('attr_accessible')
|
123
132
|
attr_accessibles[lower_model] += line
|
124
133
|
.strip
|
125
|
-
.gsub(
|
126
|
-
.split(
|
134
|
+
.gsub('attr_accessible', '')
|
135
|
+
.split(',')
|
127
136
|
.map(&:strip)
|
128
137
|
else
|
129
138
|
n.write(line)
|
@@ -131,16 +140,16 @@ rb
|
|
131
140
|
end
|
132
141
|
end
|
133
142
|
end
|
134
|
-
puts "Found attr_accessible #{
|
135
|
-
`mv #{
|
143
|
+
puts "Found attr_accessible #{attr_accessibles[lower_model].join(', ')}"
|
144
|
+
`mv #{@new_name}/app/models/#{file}.tmp #{@new_name}/app/models/#{file}`
|
136
145
|
end
|
137
146
|
|
138
147
|
def files_for(dir)
|
139
148
|
puts "Files for: #{ dir }"
|
140
149
|
files = []
|
141
150
|
Dir.foreach(dir) do |node|
|
142
|
-
next if node.start_with?(
|
143
|
-
files << node if node.end_with?(
|
151
|
+
next if node.start_with?('.')
|
152
|
+
files << node if node.end_with?('.rb')
|
144
153
|
if File.directory?("#{ dir }/#{ node }")
|
145
154
|
sub_files = files_for("#{ dir }/#{ node }")
|
146
155
|
sub_files.map! { |f| "#{ node }/#{ f }" }
|
@@ -157,7 +166,7 @@ rb
|
|
157
166
|
|
158
167
|
def upgrade_gemfile(from, to)
|
159
168
|
# gsub " for '
|
160
|
-
File.open(to,
|
169
|
+
File.open(to, 'a') do |f|
|
161
170
|
unusual_gems(from).each do |gem|
|
162
171
|
f.write(gem)
|
163
172
|
end
|
@@ -173,10 +182,10 @@ end
|
|
173
182
|
def unusual_gems(gemfile)
|
174
183
|
old_gems = File.readlines(gemfile)
|
175
184
|
old_gems.select! do |gem|
|
176
|
-
gem.strip.start_with?(
|
185
|
+
gem.strip.start_with?('gem') && !COMMON_GEMS.include?(gem.strip)
|
177
186
|
end
|
178
|
-
puts
|
179
|
-
puts
|
187
|
+
puts 'CHECK THE GEM GROUPS!!'
|
188
|
+
puts 'Special gems: '
|
180
189
|
old_gems
|
181
190
|
end
|
182
191
|
|
@@ -196,22 +205,22 @@ end
|
|
196
205
|
def app_name
|
197
206
|
@app_name ||= begin
|
198
207
|
lines = File.readlines("#{ @old_name }/config/application.rb")
|
199
|
-
lines.select! { |l| l.start_with?(
|
200
|
-
lines.first.gsub(
|
208
|
+
lines.select! { |l| l.start_with?('module') }
|
209
|
+
lines.first.gsub('module', '').strip
|
201
210
|
end
|
202
211
|
end
|
203
212
|
|
204
213
|
def copy_common_dirs
|
205
214
|
SOFT_DIR_MAPPINGS.each do |src, dest|
|
206
|
-
if Dir.
|
215
|
+
if Dir.exist?("#{ @new_name }/#{ dest }")
|
207
216
|
`cp -rn #{ @old_name }/#{ src }/* #{ @new_name }/#{ dest }/`
|
208
217
|
else
|
209
218
|
`cp -r #{ @old_name }/#{ src } #{ @new_name }`
|
210
219
|
end
|
211
220
|
end
|
212
221
|
HARD_DIR_MAPPINGS.each do |src, dest|
|
213
|
-
next if src.include?(
|
214
|
-
if Dir.
|
222
|
+
next if src.include?('wrap_parameters')
|
223
|
+
if Dir.exist?("#{ @new_name }/#{ dest }")
|
215
224
|
`cp -r #{ @old_name }/#{ src }/* #{ @new_name }/#{ dest }/`
|
216
225
|
else
|
217
226
|
`cp -r #{ @old_name }/#{ src } #{ @new_name }`
|
@@ -226,4 +235,3 @@ end
|
|
226
235
|
end
|
227
236
|
end
|
228
237
|
end
|
229
|
-
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wize_upgrader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.6
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- CJ Avilla
|
@@ -18,32 +17,30 @@ executables:
|
|
18
17
|
extensions: []
|
19
18
|
extra_rdoc_files: []
|
20
19
|
files:
|
21
|
-
- lib/wize_upgrader.rb
|
22
20
|
- bin/wize_upgrader
|
21
|
+
- lib/wize_upgrader.rb
|
23
22
|
homepage: https://github.com/w1zeman1p/wize_upgrader
|
24
23
|
licenses:
|
25
24
|
- MIT
|
25
|
+
metadata: {}
|
26
26
|
post_install_message:
|
27
27
|
rdoc_options: []
|
28
28
|
require_paths:
|
29
29
|
- lib
|
30
30
|
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
-
none: false
|
32
31
|
requirements:
|
33
|
-
- -
|
32
|
+
- - ">="
|
34
33
|
- !ruby/object:Gem::Version
|
35
34
|
version: '0'
|
36
35
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
-
none: false
|
38
36
|
requirements:
|
39
|
-
- -
|
37
|
+
- - ">="
|
40
38
|
- !ruby/object:Gem::Version
|
41
39
|
version: '0'
|
42
40
|
requirements: []
|
43
41
|
rubyforge_project:
|
44
|
-
rubygems_version:
|
42
|
+
rubygems_version: 2.2.2
|
45
43
|
signing_key:
|
46
|
-
specification_version:
|
44
|
+
specification_version: 4
|
47
45
|
summary: Upgrades rails apps from 3.2 to 4
|
48
46
|
test_files: []
|
49
|
-
has_rdoc:
|