Class: ActionDispatch::Routing::Mapper

Inherits:
Object
  • Object
show all
Defined in:
lib/route_translator/extensions/mapper.rb,
lib/route_translator/extensions/legacy/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, Metrics/PerceivedComplexity

Raises:

  • (ArgumentError)


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

def add_route(action, controller, as, options_action, _path, to, via, formatted, anchor, options_constraints, internal, options_mapping) # :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_action || @scope[:action]

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

  as   = name_for_action(as, action) if as
  path = Mapping.normalize_path URI::RFC2396_PARSER.escape(path), formatted
  ast  = Journey::Parser.parse path

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

#localizedObject



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

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