rails_best_practices 1.9.0 → 1.9.1
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.
- data/.travis.yml +4 -1
- data/Gemfile +0 -3
- data/Gemfile.lock +10 -9
- data/README.md +2 -0
- data/lib/rails_best_practices/analyzer.rb +40 -21
- data/lib/rails_best_practices/core.rb +1 -0
- data/lib/rails_best_practices/core/check.rb +12 -0
- data/lib/rails_best_practices/core/configs.rb +7 -0
- data/lib/rails_best_practices/core/error.rb +2 -1
- data/lib/rails_best_practices/core/routes.rb +11 -5
- data/lib/rails_best_practices/core/runner.rb +6 -2
- data/lib/rails_best_practices/core_ext/sexp.rb +3 -1
- data/lib/rails_best_practices/prepares.rb +5 -0
- data/lib/rails_best_practices/prepares/config_prepare.rb +21 -0
- data/lib/rails_best_practices/prepares/route_prepare.rb +24 -7
- data/lib/rails_best_practices/reviews/protect_mass_assignment_review.rb +11 -3
- data/lib/rails_best_practices/reviews/remove_unused_methods_in_models_review.rb +7 -3
- data/lib/rails_best_practices/version.rb +1 -1
- data/rails_best_practices.gemspec +1 -0
- data/spec/rails_best_practices/analyzer_spec.rb +52 -32
- data/spec/rails_best_practices/core/check_spec.rb +64 -45
- data/spec/rails_best_practices/core/checking_visitor_spec.rb +65 -64
- data/spec/rails_best_practices/core/configs_spec.rb +7 -0
- data/spec/rails_best_practices/core/controllers_spec.rb +4 -2
- data/spec/rails_best_practices/core/error_spec.rb +28 -22
- data/spec/rails_best_practices/core/helpers_spec.rb +4 -2
- data/spec/rails_best_practices/core/klasses_spec.rb +8 -6
- data/spec/rails_best_practices/core/mailers_spec.rb +4 -2
- data/spec/rails_best_practices/core/methods_spec.rb +37 -35
- data/spec/rails_best_practices/core/model_associations_spec.rb +17 -15
- data/spec/rails_best_practices/core/model_attributes_spec.rb +17 -15
- data/spec/rails_best_practices/core/models_spec.rb +4 -2
- data/spec/rails_best_practices/core/modules_spec.rb +21 -19
- data/spec/rails_best_practices/core/nil_spec.rb +23 -21
- data/spec/rails_best_practices/core/routes_spec.rb +21 -14
- data/spec/rails_best_practices/core/runner_spec.rb +17 -15
- data/spec/rails_best_practices/core_ext/sexp_spec.rb +32 -7
- data/spec/rails_best_practices/lexicals/remove_tab_check_spec.rb +35 -31
- data/spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb +35 -31
- data/spec/rails_best_practices/prepares/config_prepare_spec.rb +24 -0
- data/spec/rails_best_practices/prepares/controller_prepare_spec.rb +122 -123
- data/spec/rails_best_practices/prepares/helper_prepare_spec.rb +36 -32
- data/spec/rails_best_practices/prepares/mailer_prepare_spec.rb +12 -8
- data/spec/rails_best_practices/prepares/model_prepare_spec.rb +326 -322
- data/spec/rails_best_practices/prepares/route_prepare_spec.rb +619 -573
- data/spec/rails_best_practices/prepares/schema_prepare_spec.rb +25 -21
- data/spec/rails_best_practices/reviews/add_model_virtual_attribute_review_spec.rb +85 -87
- data/spec/rails_best_practices/reviews/always_add_db_index_review_spec.rb +224 -222
- data/spec/rails_best_practices/reviews/dry_bundler_in_capistrano_review_spec.rb +30 -26
- data/spec/rails_best_practices/reviews/isolate_seed_data_review_spec.rb +79 -75
- data/spec/rails_best_practices/reviews/keep_finders_on_their_own_model_review_spec.rb +76 -72
- data/spec/rails_best_practices/reviews/law_of_demeter_review_spec.rb +138 -140
- data/spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb +38 -34
- data/spec/rails_best_practices/reviews/move_code_into_helper_review_spec.rb +22 -18
- data/spec/rails_best_practices/reviews/move_code_into_model_review_spec.rb +57 -53
- data/spec/rails_best_practices/reviews/move_finder_to_named_scope_review_spec.rb +62 -63
- data/spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb +51 -50
- data/spec/rails_best_practices/reviews/needless_deep_nesting_review_spec.rb +140 -136
- data/spec/rails_best_practices/reviews/not_use_default_route_review_spec.rb +48 -44
- data/spec/rails_best_practices/reviews/not_use_times_ago_in_words_review_spec.rb +42 -38
- data/spec/rails_best_practices/reviews/overuse_route_customizations_review_spec.rb +151 -149
- data/spec/rails_best_practices/reviews/protect_mass_assignment_review_spec.rb +86 -55
- data/spec/rails_best_practices/reviews/remove_empty_helpers_review_spec.rb +23 -19
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_controllers_review_spec.rb +290 -286
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_helpers_review_spec.rb +76 -72
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_models_review_spec.rb +601 -597
- data/spec/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review_spec.rb +55 -54
- data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb +34 -30
- data/spec/rails_best_practices/reviews/restrict_auto_generated_routes_review_spec.rb +288 -289
- data/spec/rails_best_practices/reviews/simplify_render_in_controllers_review_spec.rb +59 -55
- data/spec/rails_best_practices/reviews/simplify_render_in_views_review_spec.rb +73 -69
- data/spec/rails_best_practices/reviews/use_before_filter_review_spec.rb +89 -98
- data/spec/rails_best_practices/reviews/use_model_association_review_spec.rb +52 -52
- data/spec/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review_spec.rb +192 -190
- data/spec/rails_best_practices/reviews/use_observer_review_spec.rb +114 -121
- data/spec/rails_best_practices/reviews/use_query_attribute_review_spec.rb +189 -190
- data/spec/rails_best_practices/reviews/use_say_with_time_in_migrations_review_spec.rb +97 -93
- data/spec/rails_best_practices/reviews/use_scope_access_review_spec.rb +146 -151
- data/spec/spec_helper.rb +11 -20
- metadata +42 -26
- data/.watchr.example +0 -65
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rails_best_practices (1.9.
|
4
|
+
rails_best_practices (1.9.1)
|
5
5
|
activesupport
|
6
|
+
awesome_print
|
6
7
|
colored
|
7
8
|
erubis
|
8
9
|
i18n
|
@@ -12,7 +13,10 @@ PATH
|
|
12
13
|
GEM
|
13
14
|
remote: http://rubygems.org/
|
14
15
|
specs:
|
15
|
-
activesupport (3.
|
16
|
+
activesupport (3.2.3)
|
17
|
+
i18n (~> 0.6)
|
18
|
+
multi_json (~> 1.0)
|
19
|
+
awesome_print (1.0.2)
|
16
20
|
colored (1.2)
|
17
21
|
diff-lcs (1.1.3)
|
18
22
|
erubis (2.7.0)
|
@@ -22,11 +26,11 @@ GEM
|
|
22
26
|
guard-rspec (0.5.7)
|
23
27
|
guard (>= 0.8.4)
|
24
28
|
haml (3.1.3)
|
25
|
-
i18n (0.
|
26
|
-
|
29
|
+
i18n (0.6.0)
|
30
|
+
multi_json (1.2.0)
|
31
|
+
progressbar (0.11.0)
|
27
32
|
rake (0.9.2.2)
|
28
33
|
rb-fsevent (0.4.3.1)
|
29
|
-
ripper (1.0.2)
|
30
34
|
rspec (2.7.0)
|
31
35
|
rspec-core (~> 2.7.0)
|
32
36
|
rspec-expectations (~> 2.7.0)
|
@@ -35,11 +39,10 @@ GEM
|
|
35
39
|
rspec-expectations (2.7.0)
|
36
40
|
diff-lcs (~> 1.1.2)
|
37
41
|
rspec-mocks (2.7.0)
|
38
|
-
sexp_processor (3.0
|
42
|
+
sexp_processor (3.2.0)
|
39
43
|
slim (1.0.4)
|
40
44
|
temple (~> 0.3.4)
|
41
45
|
tilt (~> 1.3.2)
|
42
|
-
spork (0.9.0.rc9)
|
43
46
|
temple (0.3.4)
|
44
47
|
thor (0.14.6)
|
45
48
|
tilt (1.3.3)
|
@@ -56,7 +59,5 @@ DEPENDENCIES
|
|
56
59
|
rails_best_practices!
|
57
60
|
rake
|
58
61
|
rb-fsevent
|
59
|
-
ripper
|
60
62
|
rspec
|
61
63
|
slim
|
62
|
-
spork (= 0.9.0.rc9)
|
data/README.md
CHANGED
@@ -3,6 +3,8 @@ require 'fileutils'
|
|
3
3
|
|
4
4
|
require 'progressbar'
|
5
5
|
require 'colored'
|
6
|
+
require 'ap'
|
7
|
+
|
6
8
|
|
7
9
|
module RailsBestPractices
|
8
10
|
# RailsBestPractices Analyzer helps you to analyze your rails code, according to best practices on http://rails-bestpractices.
|
@@ -15,7 +17,7 @@ module RailsBestPractices
|
|
15
17
|
#
|
16
18
|
# After analyzing, output the violations.
|
17
19
|
class Analyzer
|
18
|
-
attr_accessor :runner
|
20
|
+
attr_accessor :runner, :errors_filter_block
|
19
21
|
|
20
22
|
DEFAULT_CONFIG = File.join(File.dirname(__FILE__), "..", "..", "rails_best_practices.yml")
|
21
23
|
|
@@ -54,23 +56,15 @@ module RailsBestPractices
|
|
54
56
|
@runner.debug = true if @options["debug"]
|
55
57
|
@runner.color = !@options["without-color"]
|
56
58
|
|
57
|
-
|
58
|
-
|
59
|
-
@bar.finish if display_bar?
|
60
|
-
end
|
59
|
+
analyze_source_codes
|
60
|
+
analyze_vcs
|
61
61
|
|
62
|
-
|
63
|
-
!@options["debug"] && !@options["silent"]
|
62
|
+
errors_filter_block.call(errors) if errors_filter_block
|
64
63
|
end
|
65
64
|
|
66
65
|
# Output the analyze result.
|
67
66
|
def output
|
68
67
|
if @options["format"] == 'html'
|
69
|
-
if @options["with-hg"]
|
70
|
-
load_hg_info
|
71
|
-
elsif @options["with-git"]
|
72
|
-
load_git_info
|
73
|
-
end
|
74
68
|
output_html_errors
|
75
69
|
else
|
76
70
|
output_terminal_errors
|
@@ -172,19 +166,19 @@ module RailsBestPractices
|
|
172
166
|
|
173
167
|
# output errors on terminal.
|
174
168
|
def output_terminal_errors
|
175
|
-
|
169
|
+
errors.each { |error| plain_output(error.to_s, 'red') }
|
176
170
|
plain_output("\nPlease go to http://rails-bestpractices.com to see more useful Rails Best Practices.", 'green')
|
177
|
-
if
|
171
|
+
if errors.empty?
|
178
172
|
plain_output("\nNo warning found. Cool!", 'green')
|
179
173
|
else
|
180
|
-
plain_output("\nFound #{
|
174
|
+
plain_output("\nFound #{errors.size} warnings.", 'red')
|
181
175
|
end
|
182
176
|
end
|
183
177
|
|
184
178
|
# load hg commit and hg username info.
|
185
179
|
def load_hg_info
|
186
|
-
hg_progressbar = ProgressBar.new('Hg Info',
|
187
|
-
|
180
|
+
hg_progressbar = ProgressBar.new('Hg Info', errors.size) if display_bar?
|
181
|
+
errors.each do |error|
|
188
182
|
hg_info = `cd #{@runner.class.base_path}; hg blame -lvcu #{error.filename[@runner.class.base_path.size..-1].gsub(/^\//, "")} | sed -n /:#{error.line_number.split(',').first}:/p`
|
189
183
|
unless hg_info == ""
|
190
184
|
hg_commit_username = hg_info.split(':')[0].strip
|
@@ -198,9 +192,9 @@ module RailsBestPractices
|
|
198
192
|
|
199
193
|
# load git commit and git username info.
|
200
194
|
def load_git_info
|
201
|
-
git_progressbar = ProgressBar.new('Git Info',
|
195
|
+
git_progressbar = ProgressBar.new('Git Info', errors.size) if display_bar?
|
202
196
|
start = @runner.class.base_path =~ /\/$/ ? @runner.class.base_path.size : @runner.class.base_path.size + 1
|
203
|
-
|
197
|
+
errors.each do |error|
|
204
198
|
git_info = `cd #{@runner.class.base_path}; git blame -L #{error.line_number.split(',').first},+1 #{error.filename[start..-1]}`
|
205
199
|
unless git_info == ""
|
206
200
|
git_commit, git_username = git_info.split(/\d{4}-\d{2}-\d{2}/).first.split("(")
|
@@ -223,7 +217,7 @@ module RailsBestPractices
|
|
223
217
|
File.open(@options["output-file"], "w+") do |file|
|
224
218
|
eruby = Erubis::Eruby.new(template)
|
225
219
|
file.puts eruby.evaluate(
|
226
|
-
:errors =>
|
220
|
+
:errors => errors,
|
227
221
|
:error_types => error_types,
|
228
222
|
:textmate => @options["with-textmate"],
|
229
223
|
:mvim => @options["with-mvim"],
|
@@ -248,9 +242,34 @@ module RailsBestPractices
|
|
248
242
|
end
|
249
243
|
end
|
250
244
|
|
245
|
+
# analyze source codes.
|
246
|
+
def analyze_source_codes
|
247
|
+
@bar = ProgressBar.new('Source Codes', parse_files.size * 3) if display_bar?
|
248
|
+
["lexical", "prepare", "review"].each { |process| send(:process, process) }
|
249
|
+
@bar.finish if display_bar?
|
250
|
+
end
|
251
|
+
|
252
|
+
# analyze version control system info.
|
253
|
+
def analyze_vcs
|
254
|
+
if @options["format"] == 'html'
|
255
|
+
load_git_info if @options["with-git"]
|
256
|
+
load_hg_info if @options["with-hg"]
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
# if disaply progress bar.
|
261
|
+
def display_bar?
|
262
|
+
!@options["debug"] && !@options["silent"]
|
263
|
+
end
|
264
|
+
|
251
265
|
# unique error types.
|
252
266
|
def error_types
|
253
|
-
|
267
|
+
errors.map(&:type).uniq
|
268
|
+
end
|
269
|
+
|
270
|
+
# delegate errors to runner
|
271
|
+
def errors
|
272
|
+
@runner.errors
|
254
273
|
end
|
255
274
|
end
|
256
275
|
end
|
@@ -14,6 +14,7 @@ require 'rails_best_practices/core/methods'
|
|
14
14
|
require 'rails_best_practices/core/controllers'
|
15
15
|
require 'rails_best_practices/core/helpers'
|
16
16
|
require 'rails_best_practices/core/routes'
|
17
|
+
require 'rails_best_practices/core/configs'
|
17
18
|
|
18
19
|
require 'rails_best_practices/core_ext/sexp'
|
19
20
|
require 'rails_best_practices/core_ext/enumerable'
|
@@ -14,6 +14,7 @@ module RailsBestPractices
|
|
14
14
|
SCHEMA_FILE = /db\/schema\.rb/
|
15
15
|
HELPER_FILES = /helpers\/.*\.rb$/
|
16
16
|
DEPLOY_FILES = /config\/deploy.*\.rb/
|
17
|
+
CONFIG_FILES = /config\/(application|environment|environments\/.*)\.rb/
|
17
18
|
|
18
19
|
def initialize(options={})
|
19
20
|
options.each do |key, value|
|
@@ -47,6 +48,9 @@ module RailsBestPractices
|
|
47
48
|
# @param [Sexp] node
|
48
49
|
def node_start(node)
|
49
50
|
@node = node
|
51
|
+
if self.class.debug?
|
52
|
+
ap node
|
53
|
+
end
|
50
54
|
Array(self.class.callbacks["start_#{node.sexp_type}"]).each do |callback|
|
51
55
|
self.instance_exec node, &callback
|
52
56
|
end
|
@@ -141,6 +145,14 @@ module RailsBestPractices
|
|
141
145
|
callbacks[name] ||= []
|
142
146
|
callbacks[name] << block
|
143
147
|
end
|
148
|
+
|
149
|
+
def debug?
|
150
|
+
@debug == true
|
151
|
+
end
|
152
|
+
|
153
|
+
def debug
|
154
|
+
@debug = true
|
155
|
+
end
|
144
156
|
end
|
145
157
|
|
146
158
|
# Helper to parse the class name.
|
@@ -6,7 +6,7 @@ module RailsBestPractices
|
|
6
6
|
# it indicates the filenname, line number and error message for the violation.
|
7
7
|
class Error
|
8
8
|
attr_reader :filename, :line_number, :message, :type, :url
|
9
|
-
attr_accessor :git_commit, :git_username, :hg_commit, :hg_username
|
9
|
+
attr_accessor :git_commit, :git_username, :hg_commit, :hg_username, :highlight
|
10
10
|
|
11
11
|
def initialize(options={})
|
12
12
|
@filename = options[:filename]
|
@@ -18,6 +18,7 @@ module RailsBestPractices
|
|
18
18
|
@git_username = options[:git_username]
|
19
19
|
@hg_commit = options[:hg_commit]
|
20
20
|
@hg_username = options[:hg_username]
|
21
|
+
@highlight = false
|
21
22
|
end
|
22
23
|
|
23
24
|
def short_filename
|
@@ -8,7 +8,7 @@ module RailsBestPractices
|
|
8
8
|
# @param [String] controller name
|
9
9
|
# @param [String] action name
|
10
10
|
def add_route(namespaces, controller_name, action_name)
|
11
|
-
if controller_name.present?
|
11
|
+
if namespaces.present? || controller_name.present?
|
12
12
|
self << Route.new(namespaces, controller_name, action_name)
|
13
13
|
end
|
14
14
|
end
|
@@ -19,14 +19,20 @@ module RailsBestPractices
|
|
19
19
|
|
20
20
|
def initialize(namespaces, controller_name, action_name)
|
21
21
|
@namespaces = namespaces
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
if controller_name
|
23
|
+
entities = controller_name.split('/')
|
24
|
+
@namespaces += entities[0..-2] if entities.size > 1
|
25
|
+
@controller_name = entities.last
|
26
|
+
end
|
25
27
|
@action_name = action_name
|
26
28
|
end
|
27
29
|
|
28
30
|
def controller_name_with_namespaces
|
29
|
-
|
31
|
+
if controller_name
|
32
|
+
namespaces.map { |namespace| "#{namespace.camelize}::" }.join("") + "#{controller_name.camelize}Controller"
|
33
|
+
else
|
34
|
+
namespaces.map { |namespace| namespace.camelize }.join("::") + "Controller"
|
35
|
+
end
|
30
36
|
end
|
31
37
|
|
32
38
|
def to_s
|
@@ -3,7 +3,11 @@ require 'yaml'
|
|
3
3
|
require 'ripper'
|
4
4
|
require 'active_support/inflector'
|
5
5
|
require 'active_support/core_ext/object/blank'
|
6
|
-
|
6
|
+
begin
|
7
|
+
require 'active_support/core_ext/object/try'
|
8
|
+
rescue LoadError
|
9
|
+
require 'active_support/core_ext/try'
|
10
|
+
end
|
7
11
|
|
8
12
|
module RailsBestPractices
|
9
13
|
module Core
|
@@ -113,7 +117,7 @@ module RailsBestPractices
|
|
113
117
|
#
|
114
118
|
# @return [Array] all errors from lexicals and reviews
|
115
119
|
def errors
|
116
|
-
(@reviews + @lexicals).collect {|check| check.errors}.flatten
|
120
|
+
@errors ||= (@reviews + @lexicals).collect {|check| check.errors}.flatten
|
117
121
|
end
|
118
122
|
|
119
123
|
def after_lexical; end
|
@@ -503,7 +503,7 @@ class Sexp
|
|
503
503
|
def statements
|
504
504
|
stmts = []
|
505
505
|
node = case sexp_type
|
506
|
-
when :do_block
|
506
|
+
when :do_block, :brace_block
|
507
507
|
self[2]
|
508
508
|
when :bodystmt
|
509
509
|
self[1]
|
@@ -788,6 +788,8 @@ class Sexp
|
|
788
788
|
self[1].to_s[0..-2]
|
789
789
|
when :aref
|
790
790
|
"#{self[1]}[#{self[2]}]"
|
791
|
+
when :call, :field
|
792
|
+
"#{self.subject}.#{self.message}"
|
791
793
|
else
|
792
794
|
""
|
793
795
|
end
|
@@ -5,6 +5,7 @@ require 'rails_best_practices/prepares/schema_prepare'
|
|
5
5
|
require 'rails_best_practices/prepares/controller_prepare'
|
6
6
|
require 'rails_best_practices/prepares/route_prepare'
|
7
7
|
require 'rails_best_practices/prepares/helper_prepare'
|
8
|
+
require 'rails_best_practices/prepares/config_prepare'
|
8
9
|
|
9
10
|
module RailsBestPractices
|
10
11
|
module Prepares
|
@@ -53,6 +54,10 @@ module RailsBestPractices
|
|
53
54
|
@routes ||= Core::Routes.new
|
54
55
|
end
|
55
56
|
|
57
|
+
def configs
|
58
|
+
@configs ||= Core::Configs.new
|
59
|
+
end
|
60
|
+
|
56
61
|
# Clear all prepare objects.
|
57
62
|
def clear
|
58
63
|
instance_variables.each do |instance_variable|
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rails_best_practices/core/check'
|
3
|
+
|
4
|
+
module RailsBestPractices
|
5
|
+
module Prepares
|
6
|
+
class ConfigPrepare < Core::Check
|
7
|
+
interesting_nodes :assign
|
8
|
+
interesting_files CONFIG_FILES
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@configs = Prepares.configs
|
12
|
+
end
|
13
|
+
|
14
|
+
def start_assign(node)
|
15
|
+
if node.left_value.grep_node(:sexp_type => [:vcall, :var_ref], :to_s => "config").present?
|
16
|
+
@configs[node.left_value.to_s] = node.right_value.to_s
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -5,7 +5,7 @@ module RailsBestPractices
|
|
5
5
|
module Prepares
|
6
6
|
# Remembber routes.
|
7
7
|
class RoutePrepare < Core::Check
|
8
|
-
interesting_nodes :command, :command_call, :method_add_block, :do_block
|
8
|
+
interesting_nodes :command, :command_call, :method_add_block, :do_block, :brace_block
|
9
9
|
interesting_files ROUTE_FILES
|
10
10
|
|
11
11
|
RESOURCES_ACTIONS = %w(index show new create edit update destroy)
|
@@ -29,23 +29,37 @@ module RailsBestPractices
|
|
29
29
|
second_argument = node.arguments.all[1]
|
30
30
|
if @controller_names.last
|
31
31
|
if :bare_assoc_hash == first_argument.sexp_type
|
32
|
-
|
32
|
+
action_names = [first_argument.hash_values.first.to_s]
|
33
|
+
elsif :array == first_argument.sexp_type
|
34
|
+
action_names = first_argument.array_values.map(&:to_s)
|
33
35
|
else
|
34
|
-
|
36
|
+
action_names = [first_argument.to_s]
|
37
|
+
end
|
38
|
+
action_names.each do |action_name|
|
39
|
+
@routes.add_route(current_namespaces, current_controller_name, action_name)
|
35
40
|
end
|
36
|
-
@routes.add_route(current_namespaces, current_controller_name, action_name)
|
37
41
|
else
|
38
42
|
if :bare_assoc_hash == first_argument.sexp_type
|
39
43
|
route_node = first_argument.hash_values.first
|
40
44
|
# do not parse redirect block
|
41
45
|
return if :method_add_arg == route_node.sexp_type
|
42
46
|
controller_name, action_name = route_node.to_s.split('#')
|
43
|
-
elsif :
|
44
|
-
|
47
|
+
elsif :array == first_argument.sexp_type
|
48
|
+
first_argument.array_values.map(&:to_s).each do |action_node|
|
49
|
+
@routes.add_route(current_namespaces, controller_name, action_node.to_s)
|
50
|
+
end
|
51
|
+
return
|
52
|
+
elsif :bare_assoc_hash == second_argument.try(:sexp_type)
|
53
|
+
if second_argument.hash_value("to").present?
|
54
|
+
controller_name, action_name = second_argument.hash_value("to").to_s.split('#')
|
55
|
+
else
|
56
|
+
controller_name = current_controller_name
|
57
|
+
action_name = second_argument.hash_value("action")
|
58
|
+
end
|
45
59
|
else
|
46
60
|
controller_name, action_name = first_argument.to_s.split('/')
|
47
61
|
end
|
48
|
-
@routes.add_route(current_namespaces, controller_name.underscore, action_name)
|
62
|
+
@routes.add_route(current_namespaces, controller_name.try(:underscore), action_name)
|
49
63
|
end
|
50
64
|
when "match", "root"
|
51
65
|
options = node.arguments.all.last
|
@@ -143,6 +157,9 @@ module RailsBestPractices
|
|
143
157
|
@controller_names.pop
|
144
158
|
end
|
145
159
|
|
160
|
+
alias_method :start_brace_block, :start_do_block
|
161
|
+
alias_method :end_brace_block, :end_do_block
|
162
|
+
|
146
163
|
[:resources, :resource].each do |route_name|
|
147
164
|
class_eval <<-EOF
|
148
165
|
def add_#{route_name}_routes(node)
|