Class: RuboCop::Cop::Betterment::NonStandardActions
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Betterment::NonStandardActions
- Defined in:
- lib/rubocop/cop/betterment/non_standard_actions.rb
Constant Summary collapse
- MSG_GENERAL =
'Use a new controller instead of custom actions.'- MSG_RESOURCE_ONLY =
"Resource route refers to a non-standard action in it's 'only:' param. #{MSG_GENERAL}".freeze
- MSG_ROUTE_TO =
"Route goes to a non-standard controller action. #{MSG_GENERAL}".freeze
Instance Method Summary collapse
- #not_to_or_action?(sym) ⇒ Boolean
- #on_block(node) ⇒ Object
- #resource_with_only(node) ⇒ Object
- #route_to(node) ⇒ Object
- #routes?(node) ⇒ Object
Instance Method Details
#not_to_or_action?(sym) ⇒ Boolean
21 22 23 |
# File 'lib/rubocop/cop/betterment/non_standard_actions.rb', line 21 def not_to_or_action?(sym) !i(to action).include?(sym) end |
#on_block(node) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/rubocop/cop/betterment/non_standard_actions.rb', line 33 def on_block(node) if routes?(node) node.each_descendant(:send) do |descendant_node| check_resource_with_only(descendant_node) || check_raw_route(descendant_node) end end end |
#resource_with_only(node) ⇒ Object
17 18 19 |
# File 'lib/rubocop/cop/betterment/non_standard_actions.rb', line 17 def_node_matcher :resource_with_only, " (send nil? {:resource :resources} _ (hash <(pair (sym :only) {(array (sym $_)*) (sym $_*)} ) ...> ))\n" |
#route_to(node) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/rubocop/cop/betterment/non_standard_actions.rb', line 26 def_node_matcher :route_to, "(send nil? {:match :get :post :put :patch :delete} ({str sym} $_) (hash {\n <(pair (sym ${:to :action}) ({str sym} $_)) ...>\n (pair (sym $#not_to_or_action?) $_)*\n})?)\n" |
#routes?(node) ⇒ Object
12 13 14 |
# File 'lib/rubocop/cop/betterment/non_standard_actions.rb', line 12 def_node_matcher :routes?, " (block (send (send (send (const nil? :Rails) :application) :routes) :draw) ...)\n" |