rails_best_practices 1.19.3 → 1.19.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/CHANGELOG.md +4 -0
- data/Gemfile +0 -4
- data/Gemfile.lock +120 -0
- data/README.md +4 -1
- data/lib/rails_best_practices.rb +2 -0
- data/lib/rails_best_practices/analyzer.rb +5 -4
- data/lib/rails_best_practices/cli.rb +22 -0
- data/lib/rails_best_practices/command.rb +1 -131
- data/lib/rails_best_practices/core/check.rb +24 -23
- data/lib/rails_best_practices/core/checks_loader.rb +17 -18
- data/lib/rails_best_practices/core/methods.rb +9 -8
- data/lib/rails_best_practices/core/model_associations.rb +1 -1
- data/lib/rails_best_practices/core/runner.rb +38 -38
- data/lib/rails_best_practices/option_parser.rb +140 -0
- data/lib/rails_best_practices/prepares/controller_prepare.rb +8 -14
- data/lib/rails_best_practices/prepares/gemfile_prepare.rb +1 -1
- data/lib/rails_best_practices/prepares/initializer_prepare.rb +3 -3
- data/lib/rails_best_practices/prepares/mailer_prepare.rb +1 -1
- data/lib/rails_best_practices/prepares/model_prepare.rb +13 -13
- data/lib/rails_best_practices/prepares/route_prepare.rb +16 -15
- data/lib/rails_best_practices/prepares/schema_prepare.rb +1 -1
- data/lib/rails_best_practices/reviews/add_model_virtual_attribute_review.rb +25 -23
- data/lib/rails_best_practices/reviews/always_add_db_index_review.rb +73 -72
- data/lib/rails_best_practices/reviews/check_destroy_return_value_review.rb +2 -1
- data/lib/rails_best_practices/reviews/check_save_return_value_review.rb +4 -3
- data/lib/rails_best_practices/reviews/default_scope_is_evil_review.rb +1 -1
- data/lib/rails_best_practices/reviews/dry_bundler_in_capistrano_review.rb +1 -1
- data/lib/rails_best_practices/reviews/hash_syntax_review.rb +11 -11
- data/lib/rails_best_practices/reviews/isolate_seed_data_review.rb +8 -8
- data/lib/rails_best_practices/reviews/keep_finders_on_their_own_model_review.rb +5 -5
- data/lib/rails_best_practices/reviews/law_of_demeter_review.rb +20 -19
- data/lib/rails_best_practices/reviews/move_code_into_controller_review.rb +3 -3
- data/lib/rails_best_practices/reviews/move_code_into_helper_review.rb +5 -5
- data/lib/rails_best_practices/reviews/move_finder_to_named_scope_review.rb +5 -5
- data/lib/rails_best_practices/reviews/needless_deep_nesting_review.rb +13 -13
- data/lib/rails_best_practices/reviews/not_rescue_exception_review.rb +1 -1
- data/lib/rails_best_practices/reviews/not_use_default_route_review.rb +2 -2
- data/lib/rails_best_practices/reviews/not_use_time_ago_in_words_review.rb +1 -1
- data/lib/rails_best_practices/reviews/overuse_route_customizations_review.rb +3 -3
- data/lib/rails_best_practices/reviews/protect_mass_assignment_review.rb +32 -32
- data/lib/rails_best_practices/reviews/remove_empty_helpers_review.rb +4 -4
- data/lib/rails_best_practices/reviews/remove_unused_methods_in_controllers_review.rb +14 -14
- data/lib/rails_best_practices/reviews/remove_unused_methods_in_helpers_review.rb +6 -6
- data/lib/rails_best_practices/reviews/remove_unused_methods_in_models_review.rb +15 -15
- data/lib/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review.rb +8 -8
- data/lib/rails_best_practices/reviews/restrict_auto_generated_routes_review.rb +71 -70
- data/lib/rails_best_practices/reviews/review.rb +2 -1
- data/lib/rails_best_practices/reviews/simplify_render_in_controllers_review.rb +1 -1
- data/lib/rails_best_practices/reviews/simplify_render_in_views_review.rb +11 -11
- data/lib/rails_best_practices/reviews/use_before_filter_review.rb +12 -9
- data/lib/rails_best_practices/reviews/use_model_association_review.rb +10 -10
- data/lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb +14 -13
- data/lib/rails_best_practices/reviews/use_observer_review.rb +20 -20
- data/lib/rails_best_practices/reviews/use_parentheses_in_method_def_review.rb +6 -6
- data/lib/rails_best_practices/reviews/use_query_attribute_review.rb +44 -41
- data/lib/rails_best_practices/reviews/use_say_with_time_in_migrations_review.rb +7 -7
- data/lib/rails_best_practices/reviews/use_scope_access_review.rb +14 -14
- data/lib/rails_best_practices/reviews/use_turbo_sprockets_rails3_review.rb +1 -1
- data/lib/rails_best_practices/version.rb +1 -1
- data/rails_best_practices.gemspec +8 -8
- data/spec/rails_best_practices/analyzer_spec.rb +4 -4
- data/spec/rails_best_practices/core/error_spec.rb +6 -3
- data/spec/rails_best_practices/lexicals/long_line_check_spec.rb +21 -21
- data/spec/rails_best_practices/prepares/gemfile_prepare_spec.rb +15 -15
- data/spec/rails_best_practices/prepares/route_prepare_spec.rb +17 -15
- data/spec/rails_best_practices/reviews/hash_syntax_review_spec.rb +4 -4
- data/spec/rails_best_practices/reviews/law_of_demeter_review_spec.rb +8 -8
- data/spec/rails_best_practices/reviews/move_code_into_model_review_spec.rb +6 -6
- data/spec/rails_best_practices/reviews/protect_mass_assignment_review_spec.rb +4 -2
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_controllers_review_spec.rb +6 -4
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_helpers_review_spec.rb +8 -6
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_models_review_spec.rb +16 -14
- data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb +4 -4
- data/spec/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review_spec.rb +14 -14
- data/spec/rails_best_practices/reviews/use_parentheses_in_method_def_review_spec.rb +1 -1
- data/spec/rails_best_practices/reviews/use_turbo_sprockets_rails3_review_spec.rb +51 -51
- metadata +5 -2
@@ -20,31 +20,30 @@ module RailsBestPractices
|
|
20
20
|
private
|
21
21
|
|
22
22
|
# read the checks from yaml config.
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
def checks_from_config
|
24
|
+
@checks ||= YAML.load_file @config
|
25
|
+
end
|
26
26
|
|
27
27
|
# load all checks from the configuration
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
active_checks
|
33
|
-
end
|
28
|
+
def load_checks_from_config(&block)
|
29
|
+
checks_from_config.each_with_object([]) do |check, active_checks|
|
30
|
+
check_instance = instantiate_check(block, *check)
|
31
|
+
active_checks << check_instance unless check_instance.nil?
|
34
32
|
end
|
33
|
+
end
|
35
34
|
|
36
35
|
# instantiates a check
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
def instantiate_check(block, check_name, options)
|
37
|
+
check_class = load_check_class(check_name, &block)
|
38
|
+
check_class.new(options || {}) unless check_class.nil?
|
39
|
+
end
|
41
40
|
|
42
41
|
# loads the class for a check by calling the given block
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
42
|
+
def load_check_class(check_name)
|
43
|
+
yield(check_name)
|
44
|
+
rescue NameError
|
45
|
+
# nothing to do, the check does not exist
|
46
|
+
end
|
48
47
|
end
|
49
48
|
end
|
50
49
|
end
|
@@ -18,6 +18,7 @@ module RailsBestPractices
|
|
18
18
|
def add_method(class_name, method_name, meta = {}, access_control = 'public')
|
19
19
|
return if class_name == ''
|
20
20
|
return if has_method?(class_name, method_name)
|
21
|
+
|
21
22
|
methods(class_name) << Method.new(class_name, method_name, access_control, meta)
|
22
23
|
if access_control == 'public'
|
23
24
|
@possible_methods[method_name] = false
|
@@ -123,13 +124,13 @@ module RailsBestPractices
|
|
123
124
|
# @param [String] access control
|
124
125
|
# @return [Array] array of Method
|
125
126
|
def get_all_unused_methods(access_control = nil)
|
126
|
-
@methods.inject([])
|
127
|
+
@methods.inject([]) do |unused_methods, (_class_name, methods)|
|
127
128
|
unused_methods += if access_control
|
128
|
-
|
129
|
-
|
130
|
-
|
129
|
+
methods.select { |method| method.access_control == access_control && !method.used }
|
130
|
+
else
|
131
|
+
methods.reject(&:used)
|
131
132
|
end
|
132
|
-
|
133
|
+
end.reject { |method| method.access_control == 'public' && @possible_methods[method.method_name] }
|
133
134
|
end
|
134
135
|
|
135
136
|
private
|
@@ -138,9 +139,9 @@ module RailsBestPractices
|
|
138
139
|
#
|
139
140
|
# @param [String] class name
|
140
141
|
# @return [Array] array of methods
|
141
|
-
|
142
|
-
|
143
|
-
|
142
|
+
def methods(class_name)
|
143
|
+
@methods[class_name] ||= []
|
144
|
+
end
|
144
145
|
end
|
145
146
|
|
146
147
|
# Method info includes class name, method name, access control, file, line_number, used.
|
@@ -123,52 +123,52 @@ module RailsBestPractices
|
|
123
123
|
#
|
124
124
|
# @param [String] filename is the filename of the erb, haml or slim code.
|
125
125
|
# @param [String] content is the source code of erb, haml or slim file.
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
end
|
126
|
+
def parse_html_template(filename, content)
|
127
|
+
if filename =~ /.*\.erb$|.*\.rhtml$/
|
128
|
+
content = Erubis::OnlyRuby.new(content).src
|
129
|
+
elsif filename =~ /.*\.haml$/
|
130
|
+
begin
|
131
|
+
require 'haml'
|
132
|
+
content = Haml::Engine.new(content).precompiled
|
133
|
+
# remove \xxx characters
|
134
|
+
content.gsub!(/\\\d{3}/, '')
|
135
|
+
rescue LoadError
|
136
|
+
raise "In order to parse #{filename}, please install the haml gem"
|
137
|
+
rescue Haml::Error, SyntaxError
|
138
|
+
# do nothing, just ignore the wrong haml files.
|
139
|
+
end
|
140
|
+
elsif filename =~ /.*\.slim$/
|
141
|
+
begin
|
142
|
+
require 'slim'
|
143
|
+
content = Slim::Engine.new.call(content)
|
144
|
+
rescue LoadError
|
145
|
+
raise "In order to parse #{filename}, please install the slim gem"
|
146
|
+
rescue SyntaxError
|
147
|
+
# do nothing, just ignore the wrong slim files
|
149
148
|
end
|
150
|
-
content
|
151
149
|
end
|
150
|
+
content
|
151
|
+
end
|
152
152
|
|
153
153
|
# load all prepares.
|
154
|
-
|
155
|
-
|
156
|
-
|
154
|
+
def load_prepares
|
155
|
+
Prepares.constants.map { |prepare| Prepares.const_get(prepare).new }
|
156
|
+
end
|
157
157
|
|
158
158
|
# load all plugin reviews.
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
end
|
169
|
-
end
|
159
|
+
def load_plugin_reviews
|
160
|
+
plugins = File.join(Runner.base_path, 'lib', 'rails_best_practices', 'plugins', 'reviews')
|
161
|
+
if File.directory?(plugins)
|
162
|
+
Dir[File.expand_path(File.join(plugins, '*.rb'))].each do |review|
|
163
|
+
require review
|
164
|
+
end
|
165
|
+
if RailsBestPractices.constants.map(&:to_sym).include? :Plugins
|
166
|
+
RailsBestPractices::Plugins::Reviews.constants.each do |review|
|
167
|
+
@reviews << RailsBestPractices::Plugins::Reviews.const_get(review).new
|
170
168
|
end
|
169
|
+
end
|
171
170
|
end
|
171
|
+
end
|
172
172
|
end
|
173
173
|
end
|
174
174
|
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
|
5
|
+
module RailsBestPractices
|
6
|
+
class OptionParser
|
7
|
+
# Usage: rails_best_practices [options] path
|
8
|
+
# -d, --debug debug mode
|
9
|
+
# --silent silent mode
|
10
|
+
# -f, --format FORMAT output format (text, html, yml, json, xml)
|
11
|
+
# --output-file FILE output html file for the analyzing result
|
12
|
+
# --without-color only output plain text without color
|
13
|
+
# --with-textmate open file by textmate in html format
|
14
|
+
# --with-sublime open file by sublime in html format (requires subl-handler)
|
15
|
+
# --with-mvim open file by mvim in html format
|
16
|
+
# --with-github GITHUB_NAME open file on github in html format, GITHUB_NAME is like railsbp/rails-bestpractices.com
|
17
|
+
# --with-git display git commit and username, only support html format
|
18
|
+
# --with-hg display hg commit and username, only support html format
|
19
|
+
# --template TEMPLATE customize erb template
|
20
|
+
# --vendor include vendor files
|
21
|
+
# --spec include spec files
|
22
|
+
# --test include test files
|
23
|
+
# --features include features files
|
24
|
+
# -x, --exclude PATTERNS don't analyze files matching a pattern
|
25
|
+
# (comma-separated regexp list)
|
26
|
+
# -o, --only PATTERNS analyze files only matching a pattern
|
27
|
+
# (comma-separated regexp list)
|
28
|
+
# -g, --generate generate configuration yaml
|
29
|
+
# -v, --version show this version
|
30
|
+
# -h, --help show this message
|
31
|
+
|
32
|
+
def self.parse!(argv = ARGV)
|
33
|
+
options = {}
|
34
|
+
OptParse.new do |opts|
|
35
|
+
opts.default_argv = argv
|
36
|
+
|
37
|
+
opts.banner = 'Usage: rails_best_practices [options] path'
|
38
|
+
|
39
|
+
opts.on('-d', '--debug', 'Debug mode') do
|
40
|
+
options['debug'] = true
|
41
|
+
end
|
42
|
+
|
43
|
+
opts.on('-f', '--format FORMAT', 'output format (text, html, yml, json, xml)') do |format|
|
44
|
+
options['format'] = format
|
45
|
+
end
|
46
|
+
|
47
|
+
opts.on('--without-color', 'only output plain text without color') do
|
48
|
+
options['without-color'] = true
|
49
|
+
end
|
50
|
+
|
51
|
+
opts.on('--with-textmate', 'open file by textmate in html format') do
|
52
|
+
options['with-textmate'] = true
|
53
|
+
end
|
54
|
+
|
55
|
+
opts.on('--with-sublime', 'open file by sublime in html format') do
|
56
|
+
options['with-sublime'] = true
|
57
|
+
end
|
58
|
+
|
59
|
+
opts.on('--with-mvim', 'open file by mvim in html format') do
|
60
|
+
options['with-mvim'] = true
|
61
|
+
end
|
62
|
+
|
63
|
+
opts.on('--with-github GITHUB_NAME', 'open file on github in html format') do |github_name|
|
64
|
+
options['with-github'] = true
|
65
|
+
options['github-name'] = github_name
|
66
|
+
end
|
67
|
+
|
68
|
+
opts.on('--last-commit-id COMMIT_ID', 'last commit id') do |commit_id|
|
69
|
+
options['last-commit-id'] = commit_id
|
70
|
+
end
|
71
|
+
|
72
|
+
opts.on('--with-hg', 'display hg commit and username, only support html format') do
|
73
|
+
options['with-hg'] = true
|
74
|
+
end
|
75
|
+
|
76
|
+
opts.on('--with-git', 'display git commit and username, only support html format') do
|
77
|
+
options['with-git'] = true
|
78
|
+
end
|
79
|
+
|
80
|
+
opts.on('--template TEMPLATE', 'customize erb template') do |template|
|
81
|
+
options['template'] = template
|
82
|
+
end
|
83
|
+
|
84
|
+
opts.on('--output-file OUTPUT_FILE', 'output html file for the analyzing result') do |output_file|
|
85
|
+
options['output-file'] = output_file
|
86
|
+
end
|
87
|
+
|
88
|
+
opts.on('--silent', 'silent mode') do
|
89
|
+
options['silent'] = true
|
90
|
+
end
|
91
|
+
|
92
|
+
%w[vendor spec test features].each do |pattern|
|
93
|
+
opts.on("--#{pattern}", "include #{pattern} files") do
|
94
|
+
options[pattern] = true
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
opts.on_tail('-v', '--version', 'Show this version') do
|
99
|
+
require 'rails_best_practices/version'
|
100
|
+
puts RailsBestPractices::VERSION
|
101
|
+
exit
|
102
|
+
end
|
103
|
+
|
104
|
+
opts.on_tail('-h', '--help', 'Show this message') do
|
105
|
+
puts opts
|
106
|
+
exit
|
107
|
+
end
|
108
|
+
|
109
|
+
opts.on('-x', '--exclude PATTERNS', "Don't analyze files matching a pattern", '(comma-separated regexp list)') do |list|
|
110
|
+
begin
|
111
|
+
options['exclude'] = list.split(',').map { |x| Regexp.new x }
|
112
|
+
rescue RegexpError => e
|
113
|
+
raise OptionParser::InvalidArgument, e.message
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
opts.on('-o', '--only PATTERNS', 'Analyze files only matching a pattern', '(comma-separated regexp list)') do |list|
|
118
|
+
begin
|
119
|
+
options['only'] = list.split(',').map { |x| Regexp.new x }
|
120
|
+
rescue RegexpError => e
|
121
|
+
raise OptionParser::InvalidArgument e.message
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
opts.on('-g', '--generate', 'Generate configuration yaml') do
|
126
|
+
options['generate'] = true
|
127
|
+
end
|
128
|
+
|
129
|
+
opts.on(
|
130
|
+
'-c',
|
131
|
+
'--config CONFIG_PATH', 'configuration file location (defaults to config/rails_best_practices.yml)'
|
132
|
+
) do |config_path|
|
133
|
+
options['config'] = config_path
|
134
|
+
end
|
135
|
+
opts.parse!
|
136
|
+
end
|
137
|
+
options
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -25,14 +25,12 @@ module RailsBestPractices
|
|
25
25
|
add_callback :start_class do |_node|
|
26
26
|
@controllers << @klass
|
27
27
|
@current_controller_name = @klass.to_s
|
28
|
-
if @inherited_resources
|
29
|
-
@actions = DEFAULT_ACTIONS
|
30
|
-
end
|
28
|
+
@actions = DEFAULT_ACTIONS if @inherited_resources
|
31
29
|
end
|
32
30
|
|
33
31
|
# remember the action names at the end of class node if the controller is a InheritedResources.
|
34
32
|
add_callback :end_class do |node|
|
35
|
-
if @inherited_resources && 'ApplicationController'
|
33
|
+
if @inherited_resources && @current_controller_name != 'ApplicationController'
|
36
34
|
@actions.each do |action|
|
37
35
|
@methods.add_method(@current_controller_name, action, 'file' => node.file, 'line_number' => node.line_number)
|
38
36
|
end
|
@@ -41,27 +39,23 @@ module RailsBestPractices
|
|
41
39
|
|
42
40
|
# check if there is a DSL call inherit_resources.
|
43
41
|
add_callback :start_var_ref do |_node|
|
44
|
-
if @inherited_resources
|
45
|
-
@actions = DEFAULT_ACTIONS
|
46
|
-
end
|
42
|
+
@actions = DEFAULT_ACTIONS if @inherited_resources
|
47
43
|
end
|
48
44
|
|
49
45
|
# check if there is a DSL call inherit_resources.
|
50
46
|
add_callback :start_vcall do |_node|
|
51
|
-
if @inherited_resources
|
52
|
-
@actions = DEFAULT_ACTIONS
|
53
|
-
end
|
47
|
+
@actions = DEFAULT_ACTIONS if @inherited_resources
|
54
48
|
end
|
55
49
|
|
56
50
|
# restrict actions for inherited_resources
|
57
51
|
add_callback :start_command do |node|
|
58
|
-
if
|
52
|
+
if node.message.to_s == 'include'
|
59
53
|
@helpers.add_module_descendant(node.arguments.all.first.to_s, current_class_name)
|
60
|
-
elsif @inherited_resources &&
|
61
|
-
if
|
54
|
+
elsif @inherited_resources && node.message.to_s == 'actions'
|
55
|
+
if node.arguments.all.first.to_s == 'all'
|
62
56
|
@actions = DEFAULT_ACTIONS
|
63
57
|
option_argument = node.arguments.all[1]
|
64
|
-
if option_argument &&
|
58
|
+
if option_argument && option_argument.sexp_type == :bare_assoc_hash && option_argument.hash_value('except')
|
65
59
|
@actions -= option_argument.hash_value('except').to_object
|
66
60
|
end
|
67
61
|
else
|
@@ -21,9 +21,9 @@ module RailsBestPractices
|
|
21
21
|
# check if the node is
|
22
22
|
# ActiveRecord::Base.send(:include, ActiveModel::ForbiddenAttributesProtection)
|
23
23
|
def include_forbidden_attributes_protection?(node)
|
24
|
-
'ActiveRecord::Base'
|
25
|
-
|
26
|
-
['include', 'ActiveModel::ForbiddenAttributesProtection']
|
24
|
+
node.receiver.to_s == 'ActiveRecord::Base' &&
|
25
|
+
node.message.to_s == 'send' &&
|
26
|
+
node.arguments.all.map(&:to_s) == ['include', 'ActiveModel::ForbiddenAttributesProtection']
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
@@ -18,7 +18,7 @@ module RailsBestPractices
|
|
18
18
|
# if it is a subclass of ActionMailer::Base,
|
19
19
|
# then remember its class name.
|
20
20
|
add_callback :start_class do |_node|
|
21
|
-
if 'ActionMailer::Base'
|
21
|
+
if current_extend_class_name == 'ActionMailer::Base'
|
22
22
|
@mailers << @klass
|
23
23
|
end
|
24
24
|
end
|
@@ -21,7 +21,7 @@ module RailsBestPractices
|
|
21
21
|
|
22
22
|
# remember the class name.
|
23
23
|
add_callback :start_class do |_node|
|
24
|
-
if 'ActionMailer::Base'
|
24
|
+
if current_extend_class_name != 'ActionMailer::Base'
|
25
25
|
@models << @klass
|
26
26
|
end
|
27
27
|
end
|
@@ -40,8 +40,8 @@ module RailsBestPractices
|
|
40
40
|
# }
|
41
41
|
add_callback :start_def do |node|
|
42
42
|
if @klass &&
|
43
|
-
|
44
|
-
|
43
|
+
current_extend_class_name != 'ActionMailer::Base' &&
|
44
|
+
(classable_modules.empty? || klasses.any?)
|
45
45
|
method_name = node.method_name.to_s
|
46
46
|
@methods.add_method(current_class_name, method_name, { 'file' => node.file, 'line_number' => node.line_number }, current_access_control)
|
47
47
|
end
|
@@ -60,7 +60,7 @@ module RailsBestPractices
|
|
60
60
|
# }
|
61
61
|
# }
|
62
62
|
add_callback :start_defs do |node|
|
63
|
-
if @klass && 'ActionMailer::Base'
|
63
|
+
if @klass && current_extend_class_name != 'ActionMailer::Base'
|
64
64
|
method_name = node.method_name.to_s
|
65
65
|
@methods.add_method(current_class_name, method_name, { 'file' => node.file, 'line_number' => node.line_number }, current_access_control)
|
66
66
|
end
|
@@ -123,16 +123,16 @@ module RailsBestPractices
|
|
123
123
|
private
|
124
124
|
|
125
125
|
# remember associations, with class to association names.
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
end
|
133
|
-
association_class ||= association_name.classify
|
134
|
-
@model_associations.add_association(current_class_name, association_name, association_meta, association_class)
|
126
|
+
def remember_association(node)
|
127
|
+
association_meta = node.message.to_s
|
128
|
+
association_name = node.arguments.all.first.to_s
|
129
|
+
arguments_node = node.arguments.all.last
|
130
|
+
if arguments_node.hash_value('class_name').present?
|
131
|
+
association_class = arguments_node.hash_value('class_name').to_s
|
135
132
|
end
|
133
|
+
association_class ||= association_name.classify
|
134
|
+
@model_associations.add_association(current_class_name, association_name, association_meta, association_class)
|
135
|
+
end
|
136
136
|
end
|
137
137
|
end
|
138
138
|
end
|