Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.34 KB | None | 0 0
  1.           # Number of calls:2
  2.           # MethodName: name_for_action
  3.           # ReceiverName: ActionDispatch::Routing::Mapper::Resources
  4.           # GemName: actionpack
  5.           # GemVersion: 5.0.1
  6.           # Visibility: PROTECTED
  7.           # NilClass;NilClass -> NilClass
  8.           # NilClass;String -> String
  9.          
  10.           def name_for_action(as, action) #:nodoc:
  11.             prefix = prefix_name_for_action(as, action)
  12.             name_prefix = @scope[:as]
  13.  
  14.             if parent_resource
  15.               return nil unless as || action
  16.  
  17.               collection_name = parent_resource.collection_name
  18.               member_name = parent_resource.member_name
  19.             end
  20.  
  21.             action_name = @scope.action_name(name_prefix, prefix, collection_name, member_name)
  22.             candidate = action_name.select(&:present?).join('_')
  23.  
  24.             unless candidate.empty?
  25.               # If a name was not explicitly given, we check if it is valid
  26.               # and return nil in case it isn't. Otherwise, we pass the invalid name
  27.               # forward so the underlying router engine treats it and raises an exception.
  28.               if as.nil?
  29.                 candidate unless candidate !~ /\A[_a-z]/i || has_named_route?(candidate)
  30.               else
  31.                 candidate
  32.               end
  33.             end
  34.           end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement