rails_best_practices 0.3.15 → 0.3.16
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/VERSION +1 -1
- data/lib/rails_best_practices.rb +47 -0
- data/lib/rails_best_practices/command.rb +1 -40
- data/rails_best_practices.gemspec +1 -1
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.16
|
data/lib/rails_best_practices.rb
CHANGED
@@ -2,4 +2,51 @@ require 'rails_best_practices/checks'
|
|
2
2
|
require 'rails_best_practices/core'
|
3
3
|
|
4
4
|
module RailsBestPractices
|
5
|
+
|
6
|
+
class <<self
|
7
|
+
def analyze_files(dir = '.', options = {})
|
8
|
+
files = expand_dirs_to_files(dir)
|
9
|
+
files = model_first_sort(files)
|
10
|
+
files = add_duplicate_migrations(files)
|
11
|
+
['vendor', 'spec', 'test', 'stories'].each do |pattern|
|
12
|
+
files = ignore_files(files, "#{pattern}/") unless options[pattern]
|
13
|
+
end
|
14
|
+
files
|
15
|
+
end
|
16
|
+
|
17
|
+
def expand_dirs_to_files *dirs
|
18
|
+
extensions = ['rb', 'erb', 'haml', 'builder']
|
19
|
+
|
20
|
+
dirs.flatten.map { |p|
|
21
|
+
if File.directory? p
|
22
|
+
Dir[File.join(p, '**', "*.{#{extensions.join(',')}}")]
|
23
|
+
else
|
24
|
+
p
|
25
|
+
end
|
26
|
+
}.flatten
|
27
|
+
end
|
28
|
+
|
29
|
+
# for law_of_demeter_check
|
30
|
+
def model_first_sort files
|
31
|
+
files.sort { |a, b|
|
32
|
+
if a =~ /models\/.*rb/
|
33
|
+
-1
|
34
|
+
elsif b =~ /models\/.*rb/
|
35
|
+
1
|
36
|
+
else
|
37
|
+
a <=> b
|
38
|
+
end
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
# for always_add_db_index_check
|
43
|
+
def add_duplicate_migrations files
|
44
|
+
migration_files = files.select { |file| file.index("db/migrate") }
|
45
|
+
(files << migration_files).flatten
|
46
|
+
end
|
47
|
+
|
48
|
+
def ignore_files files, pattern
|
49
|
+
files.reject { |file| file.index(pattern) }
|
50
|
+
end
|
51
|
+
end
|
5
52
|
end
|
@@ -1,39 +1,5 @@
|
|
1
1
|
require 'optparse'
|
2
2
|
|
3
|
-
def expand_dirs_to_files *dirs
|
4
|
-
extensions = ['rb', 'erb', 'haml', 'builder']
|
5
|
-
|
6
|
-
dirs.flatten.map { |p|
|
7
|
-
if File.directory? p
|
8
|
-
Dir[File.join(p, '**', "*.{#{extensions.join(',')}}")]
|
9
|
-
else
|
10
|
-
p
|
11
|
-
end
|
12
|
-
}.flatten
|
13
|
-
end
|
14
|
-
|
15
|
-
# for law_of_demeter_check
|
16
|
-
def model_first_sort files
|
17
|
-
files.sort { |a, b|
|
18
|
-
if a =~ /models\/.*rb/
|
19
|
-
-1
|
20
|
-
elsif b =~ /models\/.*rb/
|
21
|
-
1
|
22
|
-
else
|
23
|
-
a <=> b
|
24
|
-
end
|
25
|
-
}
|
26
|
-
end
|
27
|
-
|
28
|
-
# for always_add_db_index_check
|
29
|
-
def add_duplicate_migrations files
|
30
|
-
migration_files = files.select { |file| file.index("db/migrate") }
|
31
|
-
(files << migration_files).flatten
|
32
|
-
end
|
33
|
-
|
34
|
-
def ignore_files files, pattern
|
35
|
-
files.reject { |file| file.index(pattern) }
|
36
|
-
end
|
37
3
|
|
38
4
|
options = {}
|
39
5
|
OptionParser.new do |opts|
|
@@ -60,12 +26,7 @@ end
|
|
60
26
|
runner = RailsBestPractices::Core::Runner.new
|
61
27
|
runner.set_debug if options['debug']
|
62
28
|
|
63
|
-
files =
|
64
|
-
files = model_first_sort(files)
|
65
|
-
files = add_duplicate_migrations(files)
|
66
|
-
['vendor', 'spec', 'test', 'stories'].each do |pattern|
|
67
|
-
files = ignore_files(files, "#{pattern}/") unless options[pattern]
|
68
|
-
end
|
29
|
+
files = RailsBestPractices::analyze_files(ARGV, options)
|
69
30
|
files.each { |file| runner.check_file(file) }
|
70
31
|
|
71
32
|
runner.errors.each {|error| puts error}
|