rails_best_practices 0.6.6 → 0.6.7

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.
Files changed (79) hide show
  1. data/Gemfile +0 -1
  2. data/README.md +28 -24
  3. data/Rakefile +0 -8
  4. data/install_supported_rubies.sh +2 -3
  5. data/lib/rails_best_practices.rb +8 -7
  6. data/lib/rails_best_practices/core.rb +1 -0
  7. data/lib/rails_best_practices/core/check.rb +68 -0
  8. data/lib/rails_best_practices/core/checking_visitor.rb +18 -15
  9. data/lib/rails_best_practices/core/runner.rb +22 -12
  10. data/lib/rails_best_practices/core/visitable_sexp.rb +6 -2
  11. data/lib/rails_best_practices/prepares.rb +11 -0
  12. data/lib/rails_best_practices/prepares/mailer_prepare.rb +33 -0
  13. data/lib/rails_best_practices/prepares/model_prepare.rb +60 -0
  14. data/lib/rails_best_practices/reviews.rb +23 -0
  15. data/lib/rails_best_practices/{checks/add_model_virtual_attribute_check.rb → reviews/add_model_virtual_attribute_review.rb} +6 -9
  16. data/lib/rails_best_practices/{checks/always_add_db_index_check.rb → reviews/always_add_db_index_review.rb} +9 -12
  17. data/lib/rails_best_practices/{checks/dry_bundler_in_capistrano_check.rb → reviews/dry_bundler_in_capistrano_review.rb} +8 -11
  18. data/lib/rails_best_practices/{checks/isolate_seed_data_check.rb → reviews/isolate_seed_data_review.rb} +11 -14
  19. data/lib/rails_best_practices/{checks/keep_finders_on_their_own_model_check.rb → reviews/keep_finders_on_their_own_model_review.rb} +7 -10
  20. data/lib/rails_best_practices/{checks/law_of_demeter_check.rb → reviews/law_of_demeter_review.rb} +10 -14
  21. data/lib/rails_best_practices/{checks/move_code_into_controller_check.rb → reviews/move_code_into_controller_review.rb} +8 -11
  22. data/lib/rails_best_practices/{checks/move_code_into_helper_check.rb → reviews/move_code_into_helper_review.rb} +7 -10
  23. data/lib/rails_best_practices/{checks/move_code_into_model_check.rb → reviews/move_code_into_model_review.rb} +7 -10
  24. data/lib/rails_best_practices/{checks/move_finder_to_named_scope_check.rb → reviews/move_finder_to_named_scope_review.rb} +7 -10
  25. data/lib/rails_best_practices/{checks/move_model_logic_into_model_check.rb → reviews/move_model_logic_into_model_review.rb} +8 -11
  26. data/lib/rails_best_practices/{checks/needless_deep_nesting_check.rb → reviews/needless_deep_nesting_review.rb} +8 -11
  27. data/lib/rails_best_practices/{checks/not_use_default_route_check.rb → reviews/not_use_default_route_review.rb} +7 -10
  28. data/lib/rails_best_practices/{checks/overuse_route_customizations_check.rb → reviews/overuse_route_customizations_review.rb} +10 -13
  29. data/lib/rails_best_practices/{checks/replace_complex_creation_with_factory_method_check.rb → reviews/replace_complex_creation_with_factory_method_review.rb} +8 -11
  30. data/lib/rails_best_practices/{checks/replace_instance_variable_with_local_variable_check.rb → reviews/replace_instance_variable_with_local_variable_review.rb} +7 -10
  31. data/lib/rails_best_practices/reviews/review.rb +92 -0
  32. data/lib/rails_best_practices/{checks/use_before_filter_check.rb → reviews/use_before_filter_review.rb} +8 -11
  33. data/lib/rails_best_practices/{checks/use_model_association_check.rb → reviews/use_model_association_review.rb} +8 -11
  34. data/lib/rails_best_practices/{checks/use_observer_check.rb → reviews/use_observer_review.rb} +14 -41
  35. data/lib/rails_best_practices/{checks/use_query_attribute_check.rb → reviews/use_query_attribute_review.rb} +20 -16
  36. data/lib/rails_best_practices/{checks/use_say_with_time_in_migrations_check.rb → reviews/use_say_with_time_in_migrations_review.rb} +8 -11
  37. data/lib/rails_best_practices/{checks/use_scope_access_check.rb → reviews/use_scope_access_review.rb} +8 -11
  38. data/lib/rails_best_practices/version.rb +1 -1
  39. data/rails_best_practices.gemspec +3 -2
  40. data/rails_best_practices.yml +22 -22
  41. data/rake_rubies.sh +3 -2
  42. data/spec/rails_best_practices/core/check_spec.rb +41 -0
  43. data/spec/rails_best_practices/core/checking_visitor_spec.rb +78 -0
  44. data/spec/rails_best_practices/core/visitable_sexp_spec.rb +39 -36
  45. data/spec/rails_best_practices/prepares/mailer_prepare_spec.rb +14 -0
  46. data/spec/rails_best_practices/prepares/model_prepare_spec.rb +22 -0
  47. data/spec/rails_best_practices/{checks/add_model_virtual_attribute_check_spec.rb → reviews/add_model_virtual_attribute_review_spec.rb} +17 -25
  48. data/spec/rails_best_practices/{checks/always_add_db_index_check_spec.rb → reviews/always_add_db_index_review_spec.rb} +28 -41
  49. data/spec/rails_best_practices/{checks/dry_bundler_in_capistrano_check_spec.rb → reviews/dry_bundler_in_capistrano_review_spec.rb} +7 -11
  50. data/spec/rails_best_practices/{checks/isolate_seed_data_check_spec.rb → reviews/isolate_seed_data_review_spec.rb} +13 -20
  51. data/spec/rails_best_practices/{checks/keep_finders_on_their_own_model_check_spec.rb → reviews/keep_finders_on_their_own_model_review_spec.rb} +16 -24
  52. data/spec/rails_best_practices/{checks/law_of_demeter_check_spec.rb → reviews/law_of_demeter_review_spec.rb} +24 -26
  53. data/spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb +29 -0
  54. data/spec/rails_best_practices/reviews/move_code_into_helper_review_spec.rb +24 -0
  55. data/spec/rails_best_practices/{checks/move_code_into_model_check_spec.rb → reviews/move_code_into_model_review_spec.rb} +12 -18
  56. data/spec/rails_best_practices/{checks/move_finder_to_named_scope_check_spec.rb → reviews/move_finder_to_named_scope_review_spec.rb} +12 -16
  57. data/spec/rails_best_practices/{checks/move_model_logic_into_model_check_spec.rb → reviews/move_model_logic_into_model_review_spec.rb} +7 -11
  58. data/spec/rails_best_practices/{checks/needless_deep_nesting_check_spec.rb → reviews/needless_deep_nesting_review_spec.rb} +26 -37
  59. data/spec/rails_best_practices/{checks/not_use_default_route_check_spec.rb → reviews/not_use_default_route_review_spec.rb} +13 -19
  60. data/spec/rails_best_practices/{checks/overuse_route_customizations_check_spec.rb → reviews/overuse_route_customizations_review_spec.rb} +27 -39
  61. data/spec/rails_best_practices/{checks/replace_complex_creation_with_factory_method_check_spec.rb → reviews/replace_complex_creation_with_factory_method_review_spec.rb} +10 -15
  62. data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb +31 -0
  63. data/spec/rails_best_practices/reviews/review_spec.rb +11 -0
  64. data/spec/rails_best_practices/{checks/use_before_filter_check_spec.rb → reviews/use_before_filter_review_spec.rb} +11 -17
  65. data/spec/rails_best_practices/{checks/use_model_association_check_spec.rb → reviews/use_model_association_review_spec.rb} +12 -18
  66. data/spec/rails_best_practices/{checks/use_observer_check_spec.rb → reviews/use_observer_review_spec.rb} +28 -29
  67. data/spec/rails_best_practices/reviews/use_query_attribute_review_spec.rb +190 -0
  68. data/spec/rails_best_practices/{checks/use_say_with_time_in_migrations_check_spec.rb → reviews/use_say_with_time_in_migrations_review_spec.rb} +14 -23
  69. data/spec/rails_best_practices/{checks/use_scope_access_check_spec.rb → reviews/use_scope_access_review_spec.rb} +28 -37
  70. data/spec/rails_best_practices_spec.rb +4 -4
  71. data/spec/spec_helper.rb +1 -0
  72. metadata +128 -102
  73. data/lib/rails_best_practices/checks.rb +0 -23
  74. data/lib/rails_best_practices/checks/check.rb +0 -203
  75. data/spec/rails_best_practices/checks/check_spec.rb +0 -57
  76. data/spec/rails_best_practices/checks/move_code_into_controller_check_spec.rb +0 -33
  77. data/spec/rails_best_practices/checks/move_code_into_helper_check_spec.rb +0 -28
  78. data/spec/rails_best_practices/checks/replace_instance_variable_with_local_variable_check_spec.rb +0 -36
  79. data/spec/rails_best_practices/checks/use_query_attribute_check_spec.rb +0 -192
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+ require 'rails_best_practices/reviews/move_finder_to_named_scope_review'
3
+ require 'rails_best_practices/reviews/use_model_association_review'
4
+ require 'rails_best_practices/reviews/use_scope_access_review'
5
+ require 'rails_best_practices/reviews/add_model_virtual_attribute_review'
6
+ require 'rails_best_practices/reviews/replace_complex_creation_with_factory_method_review'
7
+ require 'rails_best_practices/reviews/move_model_logic_into_model_review'
8
+ require 'rails_best_practices/reviews/overuse_route_customizations_review'
9
+ require 'rails_best_practices/reviews/needless_deep_nesting_review'
10
+ require 'rails_best_practices/reviews/not_use_default_route_review'
11
+ require 'rails_best_practices/reviews/keep_finders_on_their_own_model_review'
12
+ require 'rails_best_practices/reviews/law_of_demeter_review'
13
+ require 'rails_best_practices/reviews/use_observer_review'
14
+ require 'rails_best_practices/reviews/isolate_seed_data_review'
15
+ require 'rails_best_practices/reviews/always_add_db_index_review'
16
+ require 'rails_best_practices/reviews/use_before_filter_review'
17
+ require 'rails_best_practices/reviews/move_code_into_controller_review'
18
+ require 'rails_best_practices/reviews/move_code_into_model_review'
19
+ require 'rails_best_practices/reviews/move_code_into_helper_review'
20
+ require 'rails_best_practices/reviews/replace_instance_variable_with_local_variable_review'
21
+ require 'rails_best_practices/reviews/dry_bundler_in_capistrano_review'
22
+ require 'rails_best_practices/reviews/use_say_with_time_in_migrations_review'
23
+ require 'rails_best_practices/reviews/use_query_attribute_review'
@@ -1,17 +1,14 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/checks/check'
2
+ require 'rails_best_practices/reviews/review'
3
3
 
4
4
  module RailsBestPractices
5
- module Checks
5
+ module Reviews
6
6
  # Make sure to add a model virual attribute to simplify model creation.
7
7
  #
8
8
  # See the best practice details here http://rails-bestpractices.com/posts/4-add-model-virtual-attribute
9
9
  #
10
10
  # Implementation:
11
11
  #
12
- # Prepare process:
13
- # none
14
- #
15
12
  # Review process:
16
13
  # check method define nodes in all controller files,
17
14
  # if there are more than one [] method calls with the same subject and arguments,
@@ -26,16 +23,16 @@ module RailsBestPractices
26
23
  # end
27
24
  #
28
25
  # then the model needs to add a virtual attribute.
29
- class AddModelVirtualAttributeCheck < Check
26
+ class AddModelVirtualAttributeReview < Review
30
27
  def url
31
28
  "http://rails-bestpractices.com/posts/4-add-model-virtual-attribute"
32
29
  end
33
30
 
34
- def interesting_review_nodes
31
+ def interesting_nodes
35
32
  [:defn]
36
33
  end
37
34
 
38
- def interesting_review_files
35
+ def interesting_files
39
36
  CONTROLLER_FILES
40
37
  end
41
38
 
@@ -53,7 +50,7 @@ module RailsBestPractices
53
50
  # 5. and the subject of save or save! call node should be the same with the subject of attribute assignment nodes
54
51
  #
55
52
  # then the attribute assignment nodes can add model virtual attribute instead.
56
- def review_start_defn(node)
53
+ def start_defn(node)
57
54
  @attrasgns = {}
58
55
  node.recursive_children do |child|
59
56
  case child.node_type
@@ -1,17 +1,14 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/checks/check'
2
+ require 'rails_best_practices/reviews/review'
3
3
 
4
4
  module RailsBestPractices
5
- module Checks
6
- # Check db/schema.rb file to make sure every reference key has a database index.
5
+ module Reviews
6
+ # Review db/schema.rb file to make sure every reference key has a database index.
7
7
  #
8
8
  # See the best practice details here http://rails-bestpractices.com/posts/21-always-add-db-index
9
9
  #
10
10
  # Implementation:
11
11
  #
12
- # Prepare process:
13
- # none
14
- #
15
12
  # Review process:
16
13
  # only check the call nodes and at the end of iter node in db/schema file,
17
14
  # if the subject of call node is :create_table, then remember the table names
@@ -26,16 +23,16 @@ module RailsBestPractices
26
23
  #
27
24
  # if there are any foreign keys not existed in index columns,
28
25
  # then the foreign keys should add db index.
29
- class AlwaysAddDbIndexCheck < Check
26
+ class AlwaysAddDbIndexReview < Review
30
27
  def url
31
28
  "http://rails-bestpractices.com/posts/21-always-add-db-index"
32
29
  end
33
30
 
34
- def interesting_review_nodes
31
+ def interesting_nodes
35
32
  [:call, :iter]
36
33
  end
37
34
 
38
- def interesting_review_files
35
+ def interesting_files
39
36
  /db\/schema.rb/
40
37
  end
41
38
 
@@ -46,7 +43,7 @@ module RailsBestPractices
46
43
  @table_nodes = {}
47
44
  end
48
45
 
49
- # check call node in review process.
46
+ # check call node.
50
47
  #
51
48
  # if the message of call node is :create_table,
52
49
  # then remember the table name (@table_nodes) like
@@ -75,7 +72,7 @@ module RailsBestPractices
75
72
  # "comments" =>
76
73
  # ["post_id", "user_id"]
77
74
  # }
78
- def review_start_call(node)
75
+ def start_call(node)
79
76
  case node.message
80
77
  when :create_table
81
78
  remember_table_nodes(node)
@@ -113,7 +110,7 @@ module RailsBestPractices
113
110
  #
114
111
  # if there are any foreign keys not existed in index columns,
115
112
  # then we should add db index for that foreign keys.
116
- def review_end_iter(node)
113
+ def end_iter(node)
117
114
  first_node = node.subject
118
115
  if :call == first_node.node_type && s(:colon2, s(:const, :ActiveRecord), :Schema) == first_node.subject
119
116
  remove_only_type_foreign_keys
@@ -1,36 +1,33 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/checks/check'
2
+ require 'rails_best_practices/reviews/review'
3
3
 
4
4
  module RailsBestPractices
5
- module Checks
6
- # Check config/deploy.rb file to make sure using the bundler's capistrano recipe.
5
+ module Reviews
6
+ # Review config/deploy.rb file to make sure using the bundler's capistrano recipe.
7
7
  #
8
8
  # See the best practice details here http://rails-bestpractices.com/posts/51-dry-bundler-in-capistrano
9
9
  #
10
10
  # Implementation:
11
11
  #
12
- # Prepare process:
13
- # none
14
- #
15
12
  # Review process:
16
13
  # only check the call nodes to see if there is bundler namespace in config/deploy.rb file,
17
14
  #
18
15
  # if the message of call node is :namespace and the arguments of the call node is :bundler,
19
16
  # then it should use bundler's capistrano recipe.
20
- class DryBundlerInCapistranoCheck < Check
17
+ class DryBundlerInCapistranoReview < Review
21
18
  def url
22
19
  "http://rails-bestpractices.com/posts/51-dry-bundler-in-capistrano"
23
20
  end
24
21
 
25
- def interesting_review_nodes
22
+ def interesting_nodes
26
23
  [:call]
27
24
  end
28
25
 
29
- def interesting_review_files
26
+ def interesting_files
30
27
  /config\/deploy.rb/
31
28
  end
32
29
 
33
- # check call node in review process to see if it is with message :namespace and arguments :bundler.
30
+ # check call node to see if it is with message :namespace and arguments :bundler.
34
31
  #
35
32
  # the ruby code is
36
33
  #
@@ -41,7 +38,7 @@ module RailsBestPractices
41
38
  # then the call node is as follows
42
39
  #
43
40
  # s(:call, nil, :namespace, s(:arglist, s(:lit, :bundler)))
44
- def review_start_call(node)
41
+ def start_call(node)
45
42
  if :namespace == node.message and equal?(node.arguments[1], "bundler")
46
43
  add_error "dry bundler in capistrano"
47
44
  end
@@ -1,17 +1,14 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/checks/check'
2
+ require 'rails_best_practices/reviews/review'
3
3
 
4
4
  module RailsBestPractices
5
- module Checks
5
+ module Reviews
6
6
  # Make sure not to insert data in migration, move them to seed file.
7
7
  #
8
8
  # See the best practice details here http://rails-bestpractices.com/posts/20-isolating-seed-data.
9
9
  #
10
10
  # Implementation:
11
11
  #
12
- # Prepare process:
13
- # none
14
- #
15
12
  # Review process:
16
13
  # 1. check all local assignment and instance assignment nodes,
17
14
  # if the right value is a call node with message :new,
@@ -23,16 +20,16 @@ module RailsBestPractices
23
20
  # if the message is :save or :save!,
24
21
  # and the subject is included in new variables,
25
22
  # then it should be isolated to db seed.
26
- class IsolateSeedDataCheck < Check
23
+ class IsolateSeedDataReview < Review
27
24
  def url
28
25
  "http://rails-bestpractices.com/posts/20-isolating-seed-data"
29
26
  end
30
27
 
31
- def interesting_review_nodes
28
+ def interesting_nodes
32
29
  [:call, :lasgn, :iasgn]
33
30
  end
34
31
 
35
- def interesting_review_files
32
+ def interesting_files
36
33
  MIGRATION_FILES
37
34
  end
38
35
 
@@ -41,23 +38,23 @@ module RailsBestPractices
41
38
  @new_variables = []
42
39
  end
43
40
 
44
- # check local assignment node in review process.
41
+ # check local assignment node.
45
42
  #
46
43
  # if the right value of the node is a call node with :new message,
47
44
  # then remember it as new variables (@new_variables).
48
- def review_start_lasgn(node)
45
+ def start_lasgn(node)
49
46
  remember_new_variable(node)
50
47
  end
51
48
 
52
- # check instance assignment node in review process.
49
+ # check instance assignment node.
53
50
  #
54
51
  # if the right value of the node is a call node with :new message,
55
52
  # then remember it as new variables (@new_variables).
56
- def review_start_iasgn(node)
53
+ def start_iasgn(node)
57
54
  remember_new_variable(node)
58
55
  end
59
56
 
60
- # check the call node in review process.
57
+ # check the call node.
61
58
  #
62
59
  # if the message of the call node is :create or :create!,
63
60
  # then you should isolate it to seed data.
@@ -65,7 +62,7 @@ module RailsBestPractices
65
62
  # if the message of the call node is :save or :save!,
66
63
  # and the subject of the call node is included in @new_variables,
67
64
  # then you should isolate it to seed data.
68
- def review_start_call(node)
65
+ def start_call(node)
69
66
  if [:create, :create!].include? node.message
70
67
  add_error("isolate seed data")
71
68
  elsif [:save, :save!].include? node.message
@@ -1,17 +1,14 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/checks/check'
2
+ require 'rails_best_practices/reviews/review'
3
3
 
4
4
  module RailsBestPractices
5
- module Checks
6
- # Check model files to ake sure finders are on their own model.
5
+ module Reviews
6
+ # Review model files to ake sure finders are on their own model.
7
7
  #
8
8
  # See the best practice details here http://rails-bestpractices.com/posts/13-keep-finders-on-their-own-model.
9
9
  #
10
10
  # Implementation:
11
11
  #
12
- # Prepare process:
13
- # none
14
- #
15
12
  # Review process:
16
13
  # check all call nodes in model files.
17
14
  #
@@ -19,7 +16,7 @@ module RailsBestPractices
19
16
  # and the it calls the other model,
20
17
  # and there is a hash argument for finder,
21
18
  # then it should keep finders on its own model.
22
- class KeepFindersOnTheirOwnModelCheck < Check
19
+ class KeepFindersOnTheirOwnModelReview < Review
23
20
 
24
21
  FINDERS = [:find, :all, :first, :last]
25
22
 
@@ -27,11 +24,11 @@ module RailsBestPractices
27
24
  "http://rails-bestpractices.com/posts/13-keep-finders-on-their-own-model"
28
25
  end
29
26
 
30
- def interesting_review_nodes
27
+ def interesting_nodes
31
28
  [:call]
32
29
  end
33
30
 
34
- def interesting_review_files
31
+ def interesting_files
35
32
  MODEL_FILES
36
33
  end
37
34
 
@@ -44,7 +41,7 @@ module RailsBestPractices
44
41
  # 3. the any of its arguments is a hash (complex finder)
45
42
  #
46
43
  # then it should keep finders on its own model.
47
- def review_start_call(node)
44
+ def start_call(node)
48
45
  add_error "keep finders on their own model" if other_finder?(node)
49
46
  end
50
47
 
@@ -1,16 +1,16 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/checks/check'
2
+ require 'rails_best_practices/reviews/review'
3
3
 
4
4
  module RailsBestPractices
5
- module Checks
6
- # Check to make sure not to avoid the law of demeter.
5
+ module Reviews
6
+ # Review to make sure not to avoid the law of demeter.
7
7
  #
8
8
  # See the best practice details here http://rails-bestpractices.com/posts/15-the-law-of-demeter.
9
9
  #
10
10
  # Implementation:
11
11
  #
12
12
  # Prepare process:
13
- # only check all model files to save model names and association names.
13
+ # only review all model files to save model names and association names.
14
14
  #
15
15
  # Review process:
16
16
  # check all method calls to see if there is method call to the association object.
@@ -18,19 +18,17 @@ module RailsBestPractices
18
18
  # and whose message is an association of that model (also compare by name),
19
19
  # and outer the call node, it is also a call node,
20
20
  # then it violate the law of demeter.
21
- class LawOfDemeterCheck < Check
22
-
23
- prepare_model_associations
21
+ class LawOfDemeterReview < Review
24
22
 
25
23
  def url
26
24
  "http://rails-bestpractices.com/posts/15-the-law-of-demeter"
27
25
  end
28
26
 
29
- def interesting_review_nodes
27
+ def interesting_nodes
30
28
  [:call]
31
29
  end
32
30
 
33
- # check the call node in review process,
31
+ # check the call node,
34
32
  #
35
33
  # if the subject of the call node is also a call node,
36
34
  # and the subject of the subject call node matchs one of the class names,
@@ -43,7 +41,7 @@ module RailsBestPractices
43
41
  # )
44
42
  #
45
43
  # then it violates the law of demeter.
46
- def review_start_call(node)
44
+ def start_call(node)
47
45
  if [:lvar, :ivar].include?(node.subject.subject.node_type) && need_delegate?(node)
48
46
  add_error "law of demeter"
49
47
  end
@@ -67,10 +65,8 @@ module RailsBestPractices
67
65
  # as you see the subject of subject of the call node is [:ivar, @invoice],
68
66
  # and the message of subject of the call node is :user
69
67
  def need_delegate?(node)
70
- @associations.each do |class_name, associations|
71
- return true if equal?(node.subject.subject, class_name) && associations.find { |association| equal?(association, node.subject.message) }
72
- end
73
- false
68
+ class_name = node.subject.subject.to_s(:remove_at => true).classify
69
+ association_methods.include? model_associations[class_name][node.subject.message.to_s]
74
70
  end
75
71
 
76
72
  # only check belongs_to and has_one association.
@@ -1,20 +1,17 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/checks/check'
2
+ require 'rails_best_practices/reviews/review'
3
3
 
4
4
  module RailsBestPractices
5
- module Checks
6
- # Check a view file to make sure there is no finder, finder should be moved to controller.
5
+ module Reviews
6
+ # Review a view file to make sure there is no finder, finder should be moved to controller.
7
7
  #
8
8
  # See the best practice details here http://rails-bestpractices.com/posts/24-move-code-into-controller.
9
9
  #
10
10
  # Implementation:
11
11
  #
12
- # Prepare process:
13
- # none
14
- #
15
12
  # Review process:
16
13
  # only check all view files to see if there are finders, then the finders should be moved to controller.
17
- class MoveCodeIntoControllerCheck < Check
14
+ class MoveCodeIntoControllerReview < Review
18
15
 
19
16
  FINDERS = [:find, :all, :first, :last]
20
17
 
@@ -22,20 +19,20 @@ module RailsBestPractices
22
19
  "http://rails-bestpractices.com/posts/24-move-code-into-controller"
23
20
  end
24
21
 
25
- def interesting_review_nodes
22
+ def interesting_nodes
26
23
  [:call]
27
24
  end
28
25
 
29
- def interesting_review_files
26
+ def interesting_files
30
27
  VIEW_FILES
31
28
  end
32
29
 
33
- # check call nodes in review process.
30
+ # check call nodes.
34
31
  #
35
32
  # if the subject of the call node is a constant,
36
33
  # and the message of the call node is one of the :find, :all, :first and :last,
37
34
  # then it is a finder and should be moved to controller.
38
- def review_start_call(node)
35
+ def start_call(node)
39
36
  add_error "move code into controller" if finder?(node)
40
37
  end
41
38
 
@@ -1,9 +1,9 @@
1
1
  # encoding: utf-8
2
- require 'rails_best_practices/checks/check'
2
+ require 'rails_best_practices/reviews/review'
3
3
 
4
4
  module RailsBestPractices
5
- module Checks
6
- # Check a view file to make sure there is no complex options_for_select message call.
5
+ module Reviews
6
+ # Review a view file to make sure there is no complex options_for_select message call.
7
7
  #
8
8
  # See the best practice details here http://rails-bestpractices.com/posts/26-move-code-into-helper.
9
9
  #
@@ -11,9 +11,6 @@ module RailsBestPractices
11
11
  #
12
12
  # Implementation:
13
13
  #
14
- # Prepare process:
15
- # none
16
- #
17
14
  # Review process:
18
15
  # check al method calls to see if there is a complex options_for_select helper.
19
16
  #
@@ -21,16 +18,16 @@ module RailsBestPractices
21
18
  # and the first argument of the call node is array,
22
19
  # and the size of the array is greater than array_count defined,
23
20
  # then the options_for_select method should be moved into helper.
24
- class MoveCodeIntoHelperCheck < Check
21
+ class MoveCodeIntoHelperReview < Review
25
22
  def url
26
23
  "http://rails-bestpractices.com/posts/26-move-code-into-helper"
27
24
  end
28
25
 
29
- def interesting_review_nodes
26
+ def interesting_nodes
30
27
  [:call]
31
28
  end
32
29
 
33
- def interesting_review_files
30
+ def interesting_files
34
31
  VIEW_FILES
35
32
  end
36
33
 
@@ -44,7 +41,7 @@ module RailsBestPractices
44
41
  # if the first argument of options_for_select method call is an array,
45
42
  # and the size of the array is more than @array_count defined,
46
43
  # then the options_for_select helper should be moved into helper.
47
- def review_start_call(node)
44
+ def start_call(node)
48
45
  add_error "move code into helper (array_count >= #{@array_count})" if complex_select_options?(node)
49
46
  end
50
47