rails_best_practices 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
@@ -43,7 +43,7 @@ module RailsBestPractices
|
|
43
43
|
@foreign_keys.each do |table, foreign_key|
|
44
44
|
table_node = @table_nodes[table]
|
45
45
|
foreign_key.each do |column|
|
46
|
-
|
46
|
+
if indexed?(table, column)
|
47
47
|
add_error "always add db index (#{table} => [#{Array(column).join(', ')}])", table_node.file, table_node.line
|
48
48
|
end
|
49
49
|
end
|
@@ -66,14 +66,27 @@ module RailsBestPractices
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def add_foreign_key_column(table_name, foreign_key_column)
|
69
|
+
@foreign_keys[table_name] ||= []
|
69
70
|
if foreign_key_column =~ /_id$/
|
70
|
-
@foreign_keys[table_name]
|
71
|
-
|
71
|
+
unless @foreign_keys[table_name].find { |foreign_key| foreign_key.include? foreign_key_column }
|
72
|
+
@foreign_keys[table_name] << foreign_key_column
|
73
|
+
end
|
72
74
|
elsif foreign_key_column =~ /(.*?)_type$/
|
73
75
|
@foreign_keys[table_name].delete("#{$1}_id")
|
74
76
|
@foreign_keys[table_name] << ["#{$1}_id", foreign_key_column]
|
75
77
|
end
|
76
78
|
end
|
79
|
+
|
80
|
+
def indexed?(table, column)
|
81
|
+
index_columns = @index_columns[table]
|
82
|
+
!index_columns || !index_columns.any? { |e| greater_than(Array(e), Array(column)) }
|
83
|
+
end
|
84
|
+
|
85
|
+
def greater_than(more_array, less_array)
|
86
|
+
more_size = more_array.size
|
87
|
+
less_size = less_array.size
|
88
|
+
(more_array - less_array).size == more_size - less_size
|
89
|
+
end
|
77
90
|
end
|
78
91
|
end
|
79
92
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_best_practices
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.5.
|
9
|
+
- 2
|
10
|
+
version: 0.5.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Richard Huang
|