Class: ActionDispatch::Routing::Mapper

Inherits:
Object
  • Object
show all
Defined in:
lib/route_translator/extensions/mapper.rb

Instance Method Summary collapse

Instance Method Details

#add_route(action, controller, options, _path, to, via, formatted, anchor, options_constraints) ⇒ Object

rubocop:disable Lint/UnderscorePrefixedVariableName

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/route_translator/extensions/mapper.rb', line 15

def add_route(action, controller, options, _path, to, via, formatted, anchor, options_constraints) # :nodoc:
  return super unless @localized

  path = path_for_action(action, _path)
  raise ArgumentError, 'path is required' if path.blank?

  action = action.to_s

  default_action = options.delete(:action) || @scope[:action]

  if action =~ %r{^[\w\-\/]+$}
    default_action ||= action.tr('-', '_') unless action.include?('/')
  else
    action = nil
  end

  as = if !options.fetch(:as, true) # if it's set to nil or false
         options.delete(:as)
       else
         name_for_action(options.delete(:as), action)
       end

  path = Mapping.normalize_path URI.parser.escape(path), formatted
  ast = Journey::Parser.parse path

  mapping = Mapping.build(@scope, @set, ast, controller, default_action, to, via, formatted, options_constraints, anchor, options)
  @set.add_localized_route(mapping, ast, as, anchor, @scope, path, controller, default_action, to, via, formatted, options_constraints, options)
end

#localizedObject



8
9
10
11
12
# File 'lib/route_translator/extensions/mapper.rb', line 8

def localized
  @localized = true
  yield
  @localized = false
end