@@ -55,7 +55,7 @@ def existing_actions_usage_hash
5555 controller_name = controller . name . sub ( /Controller$/ , "" ) . underscore
5656 controller . action_methods . map { |action | "#{ controller_name } ##{ action } " }
5757 end
58- controller_actions . flatten . map { |action | [ action , 0 ] } . to_h
58+ Hash [ controller_actions . flatten . map { |action | [ action , 0 ] } ]
5959 end
6060 end
6161
@@ -78,8 +78,9 @@ def perform
7878 existing_actions_usage_hash [ action ] += 1
7979 else
8080 # there may be inheritance or implicit renders
81- controller_instance = controller_class_by_name ( route . requirements [ :controller ] ) &.new
82- unless controller_instance &.available_action? ( route . requirements [ :action ] )
81+ controller_class = controller_class_by_name ( route . requirements [ :controller ] )
82+ controller_instance = controller_class && controller_class . new
83+ unless controller_instance && controller_instance . available_action? ( route . requirements [ :action ] )
8384 if controller_instance . respond_to? ( route . requirements [ :action ] )
8485 logger . warn "No action, but responds: #{ action } "
8586 end
@@ -101,14 +102,15 @@ def unused_actions
101102 @unused_actions ||= begin
102103 # methods with special suffixes are obviously not actions, reduce noise:
103104 unused_actions_from_hash = existing_actions_usage_hash . reject do |action , count |
104- count . positive? || action . end_with? ( '?' ) || action . end_with? ( '!' ) || action . end_with? ( '=' )
105+ count > 0 || action . end_with? ( '?' ) || action . end_with? ( '!' ) || action . end_with? ( '=' )
105106 end
106107
107108 unused_actions_from_hash . keys . map do |action |
108109 controller_name , action_name = action . split ( '#' , 2 )
109- controller = controller_class_by_name ( controller_name ) &.new
110- method = controller . method ( action_name . to_sym )
111- if method &.source_location && method . source_location . first . start_with? ( root )
110+ controller_class = controller_class_by_name ( controller_name )
111+ controller = controller_class && controller_class . new
112+ method = controller && controller . method ( action_name . to_sym )
113+ if method && method . source_location && method . source_location . first . start_with? ( root )
112114 "#{ method . source_location . first . sub ( root , '' ) } :#{ method . source_location . second } - #{ action } "
113115 else
114116 action
0 commit comments