rails_best_practices 1.18.1 → 1.19.0
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.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/CHANGELOG.md +4 -1
- data/Gemfile +3 -3
- data/README.md +1 -1
- data/Rakefile +1 -4
- data/lib/rails_best_practices/analyzer.rb +3 -3
- data/lib/rails_best_practices/core/routes.rb +1 -1
- data/lib/rails_best_practices/lexicals/remove_tab_check.rb +2 -2
- data/lib/rails_best_practices/lexicals/remove_trailing_whitespace_check.rb +2 -2
- data/lib/rails_best_practices/prepares/route_prepare.rb +5 -0
- data/lib/rails_best_practices/reviews/add_model_virtual_attribute_review.rb +2 -2
- data/lib/rails_best_practices/reviews/always_add_db_index_review.rb +2 -2
- data/lib/rails_best_practices/reviews/check_save_return_value_review.rb +2 -2
- data/lib/rails_best_practices/reviews/default_scope_is_evil_review.rb +2 -2
- data/lib/rails_best_practices/reviews/dry_bundler_in_capistrano_review.rb +2 -2
- data/lib/rails_best_practices/reviews/isolate_seed_data_review.rb +2 -2
- data/lib/rails_best_practices/reviews/keep_finders_on_their_own_model_review.rb +2 -2
- data/lib/rails_best_practices/reviews/law_of_demeter_review.rb +2 -2
- data/lib/rails_best_practices/reviews/move_code_into_controller_review.rb +2 -2
- data/lib/rails_best_practices/reviews/move_code_into_helper_review.rb +2 -2
- data/lib/rails_best_practices/reviews/move_code_into_model_review.rb +2 -2
- data/lib/rails_best_practices/reviews/move_finder_to_named_scope_review.rb +2 -2
- data/lib/rails_best_practices/reviews/move_model_logic_into_model_review.rb +2 -2
- data/lib/rails_best_practices/reviews/needless_deep_nesting_review.rb +2 -2
- data/lib/rails_best_practices/reviews/not_rescue_exception_review.rb +2 -2
- data/lib/rails_best_practices/reviews/not_use_default_route_review.rb +3 -12
- data/lib/rails_best_practices/reviews/not_use_time_ago_in_words_review.rb +2 -2
- data/lib/rails_best_practices/reviews/overuse_route_customizations_review.rb +2 -47
- data/lib/rails_best_practices/reviews/protect_mass_assignment_review.rb +2 -2
- data/lib/rails_best_practices/reviews/remove_empty_helpers_review.rb +2 -2
- data/lib/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review.rb +2 -2
- data/lib/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review.rb +2 -2
- data/lib/rails_best_practices/reviews/restrict_auto_generated_routes_review.rb +15 -6
- data/lib/rails_best_practices/reviews/simplify_render_in_controllers_review.rb +2 -2
- data/lib/rails_best_practices/reviews/simplify_render_in_views_review.rb +2 -2
- data/lib/rails_best_practices/reviews/use_before_filter_review.rb +2 -2
- data/lib/rails_best_practices/reviews/use_model_association_review.rb +2 -2
- data/lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb +3 -18
- data/lib/rails_best_practices/reviews/use_observer_review.rb +2 -13
- data/lib/rails_best_practices/reviews/use_query_attribute_review.rb +2 -2
- data/lib/rails_best_practices/reviews/use_say_with_time_in_migrations_review.rb +2 -2
- data/lib/rails_best_practices/reviews/use_scope_access_review.rb +2 -2
- data/lib/rails_best_practices/reviews/use_turbo_sprockets_rails3_review.rb +2 -2
- data/lib/rails_best_practices/version.rb +1 -1
- data/rails_best_practices.gemspec +2 -2
- data/spec/rails_best_practices/analyzer_spec.rb +1 -1
- data/spec/rails_best_practices/prepares/route_prepare_spec.rb +338 -586
- data/spec/rails_best_practices/reviews/needless_deep_nesting_review_spec.rb +59 -140
- data/spec/rails_best_practices/reviews/not_use_default_route_review_spec.rb +26 -69
- data/spec/rails_best_practices/reviews/overuse_route_customizations_review_spec.rb +44 -153
- data/spec/rails_best_practices/reviews/protect_mass_assignment_review_spec.rb +2 -2
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_controllers_review_spec.rb +21 -0
- data/spec/rails_best_practices/reviews/restrict_auto_generated_routes_review_spec.rb +160 -272
- data/spec/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review_spec.rb +76 -209
- data/spec/rails_best_practices/reviews/use_observer_review_spec.rb +43 -110
- data/spec/rails_best_practices/reviews/use_turbo_sprockets_rails3_review_spec.rb +4 -4
- metadata +5 -23
- data/.rubocop.yml +0 -1
- data/.rubocop_todo.yml +0 -382
- data/install_supported_rubies.sh +0 -10
- data/rake_rubies.sh +0 -9
@@ -3,7 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Review view and helper files to make sure not use time_ago_in_words or distance_of_time_in_words_to_now.
|
5
5
|
#
|
6
|
-
# See the best practice details here
|
6
|
+
# See the best practice details here https://rails-bestpractices.com/posts/2012/02/10/not-use-time_ago_in_words/
|
7
7
|
#
|
8
8
|
# Implementation:
|
9
9
|
#
|
@@ -12,7 +12,7 @@ module RailsBestPractices
|
|
12
12
|
class NotUseTimeAgoInWordsReview < Review
|
13
13
|
interesting_nodes :fcall
|
14
14
|
interesting_files VIEW_FILES, HELPER_FILES
|
15
|
-
url "
|
15
|
+
url "https://rails-bestpractices.com/posts/2012/02/10/not-use-time_ago_in_words/"
|
16
16
|
|
17
17
|
# check fcall node to see if its message is time_ago_in_words or distance_of_time_in_words_to_now
|
18
18
|
add_callback :start_fcall do |node|
|
@@ -3,22 +3,11 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Review config/routes.rb file to make sure there are no overuse route customizations.
|
5
5
|
#
|
6
|
-
# See the best practice details here
|
6
|
+
# See the best practice details here https://rails-bestpractices.com/posts/2010/07/22/overuse-route-customizations/
|
7
7
|
#
|
8
8
|
# Implementation:
|
9
9
|
#
|
10
10
|
# Review process:
|
11
|
-
# the check methods are different for rails2 and rails3 syntax.
|
12
|
-
#
|
13
|
-
# for rails2
|
14
|
-
#
|
15
|
-
# check all command_call nodes in route file.
|
16
|
-
# if the message of command_call node is resources,
|
17
|
-
# and the second argument of command_call node is a hash,
|
18
|
-
# and the count of the pair (key/value) in hash is greater than @customize_count,
|
19
|
-
# then these custom routes are overuse.
|
20
|
-
#
|
21
|
-
# for rails3
|
22
11
|
#
|
23
12
|
# check all method_add_block nodes in route file.
|
24
13
|
# if the receiver of method_add_block node is with message resources,
|
@@ -28,7 +17,7 @@ module RailsBestPractices
|
|
28
17
|
class OveruseRouteCustomizationsReview < Review
|
29
18
|
interesting_nodes :command_call, :method_add_block
|
30
19
|
interesting_files ROUTE_FILES
|
31
|
-
url "
|
20
|
+
url "https://rails-bestpractices.com/posts/2010/07/22/overuse-route-customizations/"
|
32
21
|
|
33
22
|
VERBS = %w(get post update delete)
|
34
23
|
|
@@ -37,21 +26,7 @@ module RailsBestPractices
|
|
37
26
|
@customize_count = options['customize_count'] || 3
|
38
27
|
end
|
39
28
|
|
40
|
-
# check command_call node to see if the count of member and collection custom routes is more than @customize_count defined.
|
41
|
-
# this is for rails2 syntax.
|
42
|
-
#
|
43
|
-
# if the message of call node is "resources",
|
44
|
-
# and the second argument of call node is a hash,
|
45
|
-
# and the count of the pair (key/value) in hash is greater than @customize_count,
|
46
|
-
# then they are overuse route customizations.
|
47
|
-
add_callback :start_command_call do |node|
|
48
|
-
if member_and_collection_count_for_rails2(node) > @customize_count
|
49
|
-
add_error "overuse route customizations (customize_count > #{@customize_count})", node.file, node.receiver.line_number
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
29
|
# check method_add_block node to see if the count of member and collection custom routes is more than @customize_count defined.
|
54
|
-
# this is for rails3 syntax.
|
55
30
|
#
|
56
31
|
# if the receiver of method_add_block node is with message "resources",
|
57
32
|
# and in the block body of method_add_block node, there are more than @customize_count call nodes,
|
@@ -65,27 +40,7 @@ module RailsBestPractices
|
|
65
40
|
|
66
41
|
private
|
67
42
|
|
68
|
-
# check command_call node to calculate the count of member and collection custom routes.
|
69
|
-
# this is for rails2 syntax.
|
70
|
-
#
|
71
|
-
# if the message of command_call node is "resources",
|
72
|
-
# and the second argument is a hash,
|
73
|
-
# then calculate the pair (key/value) count,
|
74
|
-
# it is just the count of member and collection custom routes.
|
75
|
-
def member_and_collection_count_for_rails2(node)
|
76
|
-
if "resources" == node.message.to_s
|
77
|
-
hash_node = node.arguments.all.last
|
78
|
-
if hash_node && :bare_assoc_hash == hash_node.sexp_type
|
79
|
-
member_node = hash_node.hash_value("member")
|
80
|
-
collection_node = hash_node.hash_value("collection")
|
81
|
-
return (member_node.hash_size || member_node.array_size) + (collection_node.hash_size || collection_node.array_size)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
0
|
85
|
-
end
|
86
|
-
|
87
43
|
# check method_add_block node to calculate the count of member and collection custom routes.
|
88
|
-
# this is for rails3 syntax.
|
89
44
|
#
|
90
45
|
# if its receiver is with message "resources",
|
91
46
|
# then calculate the count of call nodes, whose message is get, post, update or delete,
|
@@ -3,7 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Review model files to make sure to use attr_accessible, attr_protected or strong_parameters to protect mass assignment.
|
5
5
|
#
|
6
|
-
# See the best practices details here
|
6
|
+
# See the best practices details here https://rails-bestpractices.com/posts/2012/03/06/protect-mass-assignment/
|
7
7
|
#
|
8
8
|
# Implmentation:
|
9
9
|
#
|
@@ -13,7 +13,7 @@ module RailsBestPractices
|
|
13
13
|
class ProtectMassAssignmentReview < Review
|
14
14
|
interesting_files MODEL_FILES
|
15
15
|
interesting_nodes :class, :command, :var_ref, :vcall, :fcall
|
16
|
-
url "
|
16
|
+
url "https://rails-bestpractices.com/posts/2012/03/06/protect-mass-assignment/"
|
17
17
|
|
18
18
|
# we treat it as mass assignment by default.
|
19
19
|
add_callback :start_class do |node|
|
@@ -3,7 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Review a helper file to make sure it is not an empty moduel.
|
5
5
|
#
|
6
|
-
# See the best practice details here
|
6
|
+
# See the best practice details here https://rails-bestpractices.com/posts/2011/04/09/remove-empty-helpers/
|
7
7
|
#
|
8
8
|
# Implementation:
|
9
9
|
#
|
@@ -12,7 +12,7 @@ module RailsBestPractices
|
|
12
12
|
class RemoveEmptyHelpersReview < Review
|
13
13
|
interesting_nodes :module
|
14
14
|
interesting_files HELPER_FILES
|
15
|
-
url "
|
15
|
+
url "https://rails-bestpractices.com/posts/2011/04/09/remove-empty-helpers/"
|
16
16
|
|
17
17
|
# check the body of module node, if it is nil, then it should be removed.
|
18
18
|
add_callback :start_module do |module_node|
|
data/lib/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review.rb
CHANGED
@@ -4,7 +4,7 @@ module RailsBestPractices
|
|
4
4
|
# Review a controller file to make sure that complex model creation should not exist in
|
5
5
|
# controller, should be replaced with factory method.
|
6
6
|
#
|
7
|
-
# See the best practice details here
|
7
|
+
# See the best practice details here https://rails-bestpractices.com/posts/2010/07/21/replace-complex-creation-with-factory-method/
|
8
8
|
#
|
9
9
|
# Implementation:
|
10
10
|
#
|
@@ -17,7 +17,7 @@ module RailsBestPractices
|
|
17
17
|
class ReplaceComplexCreationWithFactoryMethodReview < Review
|
18
18
|
interesting_nodes :def
|
19
19
|
interesting_files CONTROLLER_FILES
|
20
|
-
url "
|
20
|
+
url "https://rails-bestpractices.com/posts/2010/07/21/replace-complex-creation-with-factory-method/"
|
21
21
|
|
22
22
|
def initialize(options = {})
|
23
23
|
super(options)
|
data/lib/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review.rb
CHANGED
@@ -3,7 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Review a partail view file to make sure there is no instance variable.
|
5
5
|
#
|
6
|
-
# See the best practice details here
|
6
|
+
# See the best practice details here https://rails-bestpractices.com/posts/2010/07/24/replace-instance-variable-with-local-variable/
|
7
7
|
#
|
8
8
|
# Implementation:
|
9
9
|
#
|
@@ -13,7 +13,7 @@ module RailsBestPractices
|
|
13
13
|
class ReplaceInstanceVariableWithLocalVariableReview < Review
|
14
14
|
interesting_nodes :var_ref, :vcall
|
15
15
|
interesting_files PARTIAL_VIEW_FILES
|
16
|
-
url "
|
16
|
+
url "https://rails-bestpractices.com/posts/2010/07/24/replace-instance-variable-with-local-variable/"
|
17
17
|
|
18
18
|
# check ivar node in partial view file,
|
19
19
|
# it is an instance variable, and should be replaced with local variable.
|
@@ -3,7 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Review a route file to make sure all auto-generated routes have corresponding actions in controller.
|
5
5
|
#
|
6
|
-
# See the best practice details here
|
6
|
+
# See the best practice details here https://rails-bestpractices.com/posts/2011/08/19/restrict-auto-generated-routes/
|
7
7
|
#
|
8
8
|
# Implementation:
|
9
9
|
#
|
@@ -15,10 +15,19 @@ module RailsBestPractices
|
|
15
15
|
class RestrictAutoGeneratedRoutesReview < Review
|
16
16
|
interesting_nodes :command, :command_call, :method_add_block
|
17
17
|
interesting_files ROUTE_FILES
|
18
|
-
url "
|
18
|
+
url "https://rails-bestpractices.com/posts/2011/08/19/restrict-auto-generated-routes/"
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
def resource_methods
|
21
|
+
if Prepares.configs['config.api_only']
|
22
|
+
%w(show create update destroy)
|
23
|
+
else
|
24
|
+
%w(show new create edit update destroy)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def resources_methods
|
29
|
+
resource_methods + ['index']
|
30
|
+
end
|
22
31
|
|
23
32
|
def initialize(options={})
|
24
33
|
super(options)
|
@@ -88,12 +97,12 @@ module RailsBestPractices
|
|
88
97
|
|
89
98
|
# check resources call, if the routes generated by resources does not exist in the controller.
|
90
99
|
def check_resources(node)
|
91
|
-
_check(node,
|
100
|
+
_check(node, resources_methods)
|
92
101
|
end
|
93
102
|
|
94
103
|
# check resource call, if the routes generated by resources does not exist in the controller.
|
95
104
|
def check_resource(node)
|
96
|
-
_check(node,
|
105
|
+
_check(node, resource_methods)
|
97
106
|
end
|
98
107
|
|
99
108
|
# get the controller name.
|
@@ -3,7 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Review a controller file to make sure using simplified syntax for render.
|
5
5
|
#
|
6
|
-
# See the best practice details here
|
6
|
+
# See the best practice details here https://rails-bestpractices.com/posts/2010/12/12/simplify-render-in-controllers/
|
7
7
|
#
|
8
8
|
# Implementation:
|
9
9
|
#
|
@@ -14,7 +14,7 @@ module RailsBestPractices
|
|
14
14
|
class SimplifyRenderInControllersReview < Review
|
15
15
|
interesting_nodes :command
|
16
16
|
interesting_files CONTROLLER_FILES
|
17
|
-
url "
|
17
|
+
url "https://rails-bestpractices.com/posts/2010/12/12/simplify-render-in-controllers/"
|
18
18
|
|
19
19
|
# check command node in the controller file,
|
20
20
|
# if its message is render and the arguments contain a key action, template or file,
|
@@ -3,7 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Review a view file to make sure using simplified syntax for render.
|
5
5
|
#
|
6
|
-
# See the best practice details here
|
6
|
+
# See the best practice details here https://rails-bestpractices.com/posts/2010/12/04/simplify-render-in-views/
|
7
7
|
#
|
8
8
|
# Implementation:
|
9
9
|
#
|
@@ -13,7 +13,7 @@ module RailsBestPractices
|
|
13
13
|
class SimplifyRenderInViewsReview < Review
|
14
14
|
interesting_nodes :command
|
15
15
|
interesting_files VIEW_FILES
|
16
|
-
url "
|
16
|
+
url "https://rails-bestpractices.com/posts/2010/12/04/simplify-render-in-views/"
|
17
17
|
|
18
18
|
VALID_KEYS = %w(object collection locals)
|
19
19
|
|
@@ -4,7 +4,7 @@ module RailsBestPractices
|
|
4
4
|
# Review a controller file to make sure to use before_filter to remove duplicated first code
|
5
5
|
# line_number in different action.
|
6
6
|
#
|
7
|
-
# See the best practice detailed here
|
7
|
+
# See the best practice detailed here https://rails-bestpractices.com/posts/2010/07/24/use-before_filter/
|
8
8
|
#
|
9
9
|
# Implementation:
|
10
10
|
#
|
@@ -14,7 +14,7 @@ module RailsBestPractices
|
|
14
14
|
class UseBeforeFilterReview < Review
|
15
15
|
interesting_nodes :class
|
16
16
|
interesting_files CONTROLLER_FILES
|
17
|
-
url "
|
17
|
+
url "https://rails-bestpractices.com/posts/2010/07/24/use-before_filter/"
|
18
18
|
|
19
19
|
def initialize(options = {})
|
20
20
|
super()
|
@@ -3,7 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# review a controller file to make sure to use model association instead of foreign key id assignment.
|
5
5
|
#
|
6
|
-
# See the best practice details here
|
6
|
+
# See the best practice details here https://rails-bestpractices.com/posts/2010/07/19/use-model-association/
|
7
7
|
#
|
8
8
|
# Implementation:
|
9
9
|
#
|
@@ -16,7 +16,7 @@ module RailsBestPractices
|
|
16
16
|
class UseModelAssociationReview < Review
|
17
17
|
interesting_nodes :def
|
18
18
|
interesting_files CONTROLLER_FILES
|
19
|
-
url "
|
19
|
+
url "https://rails-bestpractices.com/posts/2010/07/19/use-model-association/"
|
20
20
|
|
21
21
|
# check method define nodes to see if there are some attribute assignments that can use model association instead.
|
22
22
|
#
|
data/lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb
CHANGED
@@ -3,7 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Make sure to use multipart/alternative as content_type of email.
|
5
5
|
#
|
6
|
-
# See the best practice details here
|
6
|
+
# See the best practice details here https://rails-bestpractices.com/posts/2010/08/05/use-multipart-alternative-as-content_type-of-email/
|
7
7
|
#
|
8
8
|
# Implementation:
|
9
9
|
#
|
@@ -13,7 +13,7 @@ module RailsBestPractices
|
|
13
13
|
class UseMultipartAlternativeAsContentTypeOfEmailReview < Review
|
14
14
|
interesting_nodes :class, :def
|
15
15
|
interesting_files MAILER_FILES
|
16
|
-
url "
|
16
|
+
url "https://rails-bestpractices.com/posts/2010/08/05/use-multipart-alternative-as-content_type-of-email/"
|
17
17
|
|
18
18
|
# check class node to remember the ActionMailer class name.
|
19
19
|
add_callback :start_class do |node|
|
@@ -23,7 +23,7 @@ module RailsBestPractices
|
|
23
23
|
# check def node and find if the corresponding views exist or not?
|
24
24
|
add_callback :start_def do |node|
|
25
25
|
name = node.method_name.to_s
|
26
|
-
if !
|
26
|
+
if !rails3_canonical_mailer_views?(name)
|
27
27
|
add_error("use multipart/alternative as content_type of email")
|
28
28
|
end
|
29
29
|
end
|
@@ -34,21 +34,6 @@ module RailsBestPractices
|
|
34
34
|
#
|
35
35
|
# @param [String] name method name in action_mailer
|
36
36
|
def rails_canonical_mailer_views?(name)
|
37
|
-
if Prepares.gems.gem_version("rails").to_i > 2
|
38
|
-
rails3_canonical_mailer_views?(name)
|
39
|
-
else
|
40
|
-
rails2_canonical_mailer_views?(name)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
# check if rails2's syntax mailer views are canonical.
|
45
|
-
#
|
46
|
-
# @param [String] name method name in action_mailer
|
47
|
-
def rails2_canonical_mailer_views?(name)
|
48
|
-
return true if mailer_files(name).length == 0
|
49
|
-
return true if mailer_files(name).none? { |filename| filename.index 'text.html' }
|
50
|
-
mailer_files(name).any? { |filename| filename.index 'text.html' } &&
|
51
|
-
mailer_files(name).any? { |filename| filename.index 'text.plain' }
|
52
37
|
end
|
53
38
|
|
54
39
|
# check if rails3's syntax mailer views are canonical.
|
@@ -3,7 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Make sure to use observer (sorry we only check the mailer deliver now).
|
5
5
|
#
|
6
|
-
# See the best practice details here
|
6
|
+
# See the best practice details here https://rails-bestpractices.com/posts/2010/07/24/use-observer/
|
7
7
|
#
|
8
8
|
# TODO: we need a better solution, any suggestion?
|
9
9
|
#
|
@@ -20,7 +20,7 @@ module RailsBestPractices
|
|
20
20
|
class UseObserverReview < Review
|
21
21
|
interesting_nodes :def, :command
|
22
22
|
interesting_files MODEL_FILES
|
23
|
-
url "
|
23
|
+
url "https://rails-bestpractices.com/posts/2010/07/24/use-observer/"
|
24
24
|
|
25
25
|
def initialize(options = {})
|
26
26
|
super
|
@@ -66,22 +66,11 @@ module RailsBestPractices
|
|
66
66
|
|
67
67
|
# check a def node to see if it contains a actionmailer deliver call.
|
68
68
|
#
|
69
|
-
# for rails2
|
70
|
-
#
|
71
|
-
# if the message of call node is deliver_xxx,
|
72
|
-
# and the receiver of the call node exists in @callbacks,
|
73
|
-
#
|
74
|
-
# for rails3
|
75
|
-
#
|
76
69
|
# if the message of call node is deliver,
|
77
70
|
# and the receiver of the call node is with receiver node who exists in @callbacks,
|
78
|
-
#
|
79
71
|
# then the call node is actionmailer deliver call.
|
80
72
|
def deliver_mailer?(node)
|
81
73
|
node.grep_nodes(sexp_type: :call) do |child_node|
|
82
|
-
# rails2 actionmailer deliver
|
83
|
-
return true if child_node.message.to_s =~ /^deliver_/ && mailers.include?(child_node.receiver.to_s)
|
84
|
-
# rails3 actionmailer deliver
|
85
74
|
if "deliver" == child_node.message.to_s
|
86
75
|
if :method_add_arg == child_node.receiver.sexp_type &&
|
87
76
|
mailers.include?(child_node.receiver[1].receiver.to_s)
|
@@ -3,7 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Make sure to use query attribute instead of nil?, blank? and present?.
|
5
5
|
#
|
6
|
-
# See the best practice details here
|
6
|
+
# See the best practice details here https://rails-bestpractices.com/posts/2010/10/03/use-query-attribute/
|
7
7
|
#
|
8
8
|
# Implementation:
|
9
9
|
#
|
@@ -16,7 +16,7 @@ module RailsBestPractices
|
|
16
16
|
class UseQueryAttributeReview < Review
|
17
17
|
interesting_nodes :if, :unless, :elsif, :ifop, :if_mod, :unless_mod
|
18
18
|
interesting_files ALL_FILES
|
19
|
-
url "
|
19
|
+
url "https://rails-bestpractices.com/posts/2010/10/03/use-query-attribute/"
|
20
20
|
|
21
21
|
QUERY_METHODS = %w(nil? blank? present?)
|
22
22
|
|
@@ -4,7 +4,7 @@ module RailsBestPractices
|
|
4
4
|
# Review a migration file to make sure to use say or say_with_time for customized data changes
|
5
5
|
# to produce a more readable output.
|
6
6
|
#
|
7
|
-
# See the best practice detials here
|
7
|
+
# See the best practice detials here https://rails-bestpractices.com/posts/2010/08/19/use-say-and-say_with_time-in-migrations-to-make-a-useful-migration-log/
|
8
8
|
#
|
9
9
|
# Implementation:
|
10
10
|
#
|
@@ -16,7 +16,7 @@ module RailsBestPractices
|
|
16
16
|
class UseSayWithTimeInMigrationsReview < Review
|
17
17
|
interesting_nodes :defs
|
18
18
|
interesting_files MIGRATION_FILES
|
19
|
-
url "
|
19
|
+
url "https://rails-bestpractices.com/posts/2010/08/19/use-say-and-say_with_time-in-migrations-to-make-a-useful-migration-log/"
|
20
20
|
|
21
21
|
WITH_SAY_METHODS = %w(say say_with_time)
|
22
22
|
|
@@ -3,7 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Review a controller to make sure to use scope access instead of manually checking current_user and redirect.
|
5
5
|
#
|
6
|
-
# See the best practice details here
|
6
|
+
# See the best practice details here https://rails-bestpractices.com/posts/2010/07/20/use-scope-access/
|
7
7
|
#
|
8
8
|
# Implementation:
|
9
9
|
#
|
@@ -16,7 +16,7 @@ module RailsBestPractices
|
|
16
16
|
class UseScopeAccessReview < Review
|
17
17
|
interesting_nodes :if, :unless, :elsif, :ifop, :if_mod, :unless_mod
|
18
18
|
interesting_files CONTROLLER_FILES
|
19
|
-
url "
|
19
|
+
url "https://rails-bestpractices.com/posts/2010/07/20/use-scope-access/"
|
20
20
|
|
21
21
|
# check if node.
|
22
22
|
#
|
@@ -3,7 +3,7 @@ module RailsBestPractices
|
|
3
3
|
module Reviews
|
4
4
|
# Prepare Gemfile and review Capfile file to make sure using turbo-sprocket-rails3
|
5
5
|
#
|
6
|
-
# See the best practice details here
|
6
|
+
# See the best practice details here https://rails-bestpractices.com/posts/2012/11/23/speed-up-assets-precompile-with-turbo-sprockets-rails3/
|
7
7
|
#
|
8
8
|
# Implementation:
|
9
9
|
#
|
@@ -12,7 +12,7 @@ module RailsBestPractices
|
|
12
12
|
class UseTurboSprocketsRails3Review < Review
|
13
13
|
interesting_nodes :command
|
14
14
|
interesting_files CAPFILE
|
15
|
-
url "
|
15
|
+
url "https://rails-bestpractices.com/posts/2012/11/23/speed-up-assets-precompile-with-turbo-sprockets-rails3/"
|
16
16
|
|
17
17
|
# check command node to see if load 'deploy/assets'
|
18
18
|
add_callback :start_command do |node|
|