-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_rails
executable file
·70 lines (63 loc) · 1.76 KB
/
find_rails
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env ruby
require 'find'
require 'rubygems'
require 'thor'
# Take a directory, and a list of patterns to match, and a list of
# filenames to avoid
def recursive_search(dir,patterns, excludes=[/\.git/, /\.svn/, /,v$/, /\.cvs$/, /\.tmp$/, /^RCS$/, /^SCCS$/, /~$/])
results = Hash.new{|h,k| h[k] = ''}
Find.find(dir) do |path|
fb = File.basename(path)
next if excludes.any?{|e| fb =~ e}
if File.directory?(path)
if fb =~ /\.{1,2}/
Find.prune
else
next
end
else # file...
File.open(path, 'r') do |f|
ln = 1
while (line = f.gets)
patterns.each do |p|
if line.include?(p)
results[p] += "#{path}:#{ln}:#{line}"
end
end
ln += 1
end
end
end
end
return results
end
class FindRails < Thor
desc 'conversion [PATH_TO_APP]', "Checks your code and prints out which methods will need to change"
def conversion(path_to_app='.')
conversions = {
'before_filter' => 'Use before',
'after_filter' => 'Use after',
'render :partial' => 'Use partial',
'redirect_to' => 'Use redirect',
'url_for' => 'Use url'
}
dir_to_search = File.expand_path('app', path_to_app)
if !File.exists?(dir_to_search)
puts "#{dir_to_search} doesn't exist. Make sure you're in your merb app top level, or pass in a path to the app"
return
end
results = recursive_search(dir_to_search,conversions.keys)
conversions.each do |key, warning|
puts '--> ' + key
unless results[key] =~ /^$/
puts " !! " + warning + " !!"
puts ' ' + '.' * (warning.length + 6)
puts results[key]
else
puts " Clean! Cheers for you!"
end
puts
end
end
end
FindRails.new.conversion(ARGV.to_s)