rails_best_practices 0.3.14 → 0.3.15
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/rails_best_practices/checks/always_add_db_index_check.rb +3 -3
- data/lib/rails_best_practices/checks/check.rb +4 -3
- data/lib/rails_best_practices/checks/use_before_filter_check.rb +6 -4
- data/rails_best_practices.gemspec +2 -2
- data/spec/rails_best_practices/checks/use_before_filter_check_spec.rb +1 -1
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.15
|
@@ -56,20 +56,20 @@ module RailsBestPractices
|
|
56
56
|
node.grep_nodes({:node_type => :call, :message => :integer}).each do |integer_node|
|
57
57
|
column_name = integer_node.arguments[1].to_ruby_string
|
58
58
|
if column_name =~ /_id$/ and !@@indexes[table_name].include? column_name
|
59
|
-
add_error "always add db index (#{table_name} => #{column_name})", integer_node
|
59
|
+
add_error "always add db index (#{table_name} => #{column_name})", integer_node.file, integer_node.line
|
60
60
|
end
|
61
61
|
end
|
62
62
|
node.grep_nodes({:node_type => :call, :message => :references}).each do |references_node|
|
63
63
|
column_name = references_node.arguments[1].to_ruby_string + "_id"
|
64
64
|
if !@@indexes[table_name].include? column_name
|
65
|
-
add_error "always add db index (#{table_name} => #{column_name})", references_node
|
65
|
+
add_error "always add db index (#{table_name} => #{column_name})", references_node.file, references_node.line
|
66
66
|
end
|
67
67
|
end
|
68
68
|
node.grep_nodes({:node_type => :call, :message => :column}).each do |column_node|
|
69
69
|
if 'integer' == column_node.arguments[2].to_ruby_string
|
70
70
|
column_name = column_node.arguments[1].to_ruby_string
|
71
71
|
if column_name =~ /_id$/ and !@@indexes[table_name].include? column_name
|
72
|
-
add_error "always add db index (#{table_name} => #{column_name})", column_node
|
72
|
+
add_error "always add db index (#{table_name} => #{column_name})", column_node.file, column_node.line
|
73
73
|
end
|
74
74
|
end
|
75
75
|
end
|
@@ -52,9 +52,10 @@ module RailsBestPractices
|
|
52
52
|
evaluate_end(node)
|
53
53
|
end
|
54
54
|
|
55
|
-
def add_error(error,
|
56
|
-
|
57
|
-
|
55
|
+
def add_error(error, file = nil, line = nil)
|
56
|
+
file ||= @node.file
|
57
|
+
line ||= @node.line
|
58
|
+
@errors << RailsBestPractices::Core::Error.new("#{file}", "#{line}", error)
|
58
59
|
end
|
59
60
|
|
60
61
|
def errors
|
@@ -18,19 +18,21 @@ module RailsBestPractices
|
|
18
18
|
def evaluate_start(node)
|
19
19
|
@methods = {}
|
20
20
|
node.grep_nodes({:node_type => :defn}).each { |method_node| remember_method(method_node) }
|
21
|
-
@methods.each do |first_call,
|
22
|
-
|
21
|
+
@methods.each do |first_call, method_nodes|
|
22
|
+
if method_nodes.size > 1
|
23
|
+
add_error "use before_filter for #{method_nodes.collect{|method_node| method_node.message_name}.join(',')}",
|
24
|
+
node.file, method_nodes.collect{|method_node| method_node.line}.join(',')
|
25
|
+
end
|
23
26
|
end
|
24
27
|
end
|
25
28
|
|
26
29
|
private
|
27
30
|
|
28
31
|
def remember_method(method_node)
|
29
|
-
method_name = method_node.message_name
|
30
32
|
first_call = method_node.body[1]
|
31
33
|
unless first_call == s(:nil)
|
32
34
|
@methods[first_call] ||= []
|
33
|
-
@methods[first_call] <<
|
35
|
+
@methods[first_call] << method_node
|
34
36
|
end
|
35
37
|
end
|
36
38
|
end
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rails_best_practices}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.15"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Richard Huang"]
|
12
|
-
s.date = %q{2009-12-
|
12
|
+
s.date = %q{2009-12-22}
|
13
13
|
s.default_executable = %q{rails_best_practices}
|
14
14
|
s.description = %q{check rails files according to ihower's presentation 'rails best practices'}
|
15
15
|
s.email = %q{flyerhzm@gmail.com}
|
@@ -32,7 +32,7 @@ describe RailsBestPractices::Checks::UseBeforeFilterCheck do
|
|
32
32
|
@runner.check('app/controllers/posts_controller.rb', content)
|
33
33
|
errors = @runner.errors
|
34
34
|
errors.should_not be_empty
|
35
|
-
errors[0].to_s.should == "app/controllers/posts_controller.rb:
|
35
|
+
errors[0].to_s.should == "app/controllers/posts_controller.rb:3,7,11,16 - use before_filter for show,edit,update,destroy"
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should not use before_filter" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_best_practices
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Huang
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-22 00:00:00 +08:00
|
13
13
|
default_executable: rails_best_practices
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|