Skip to content

Commit

Permalink
Rails edge compatibility
Browse files Browse the repository at this point in the history
Close #323
  • Loading branch information
tagliala committed Dec 22, 2024
1 parent e4fbb15 commit 6da3cab
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
6 changes: 3 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Layout/LineLength:
Enabled: false

Metrics/AbcSize:
Max: 23 # TODO: Lower to 15
Max: 20 # TODO: Lower to 17
Exclude:
- 'test/**/*'

Expand All @@ -37,7 +37,7 @@ Metrics/CyclomaticComplexity:
- 'test/**/*'

Metrics/MethodLength:
Max: 19
Max: 15
Exclude:
- 'test/**/*'

Expand All @@ -46,7 +46,7 @@ Metrics/ModuleLength:
- 'test/**/*'

Metrics/ParameterLists:
Max: 12
Max: 13

Metrics/PerceivedComplexity:
Exclude:
Expand Down
21 changes: 8 additions & 13 deletions lib/route_translator/extensions/mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,28 @@ def localized
end

# rubocop:disable Lint/UnderscorePrefixedVariableName, Metrics/PerceivedComplexity
def add_route(action, controller, options, _path, to, via, formatted, anchor, options_constraints) # :nodoc:
def add_route(action, controller, as, options_action, _path, to, via, formatted, anchor, options_constraints, internal, options_mapping)
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]
default_action = options_action || @scope[:action]

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

as = if options.fetch(:as, true)
name_for_action(options.delete(:as), action)
else
options.delete(:as)
end
as = name_for_action(as, action) if as
path = Mapping.normalize_path URI::RFC2396_PARSER.escape(path), formatted
ast = Journey::Parser.parse path

path = Mapping.normalize_path URI::DEFAULT_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, as, anchor, @scope, path, controller, default_action, to, via, formatted, options_constraints, options)
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
# rubocop:enable Lint/UnderscorePrefixedVariableName, Metrics/PerceivedComplexity

Expand Down
10 changes: 5 additions & 5 deletions lib/route_translator/extensions/route_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
module ActionDispatch
module Routing
class RouteSet
def add_localized_route(mapping, name, anchor, scope, path, controller, default_action, to, via, formatted, options_constraints, options)
route = RouteTranslator::Route.new(self, path, name, options_constraints, options, mapping)
def add_localized_route(mapping, name, anchor, scope, path, controller, default_action, to, via, formatted, options_constraints, internal, options_mapping)
route = RouteTranslator::Route.new(self, path, name, options_constraints, options_mapping, mapping)

RouteTranslator::Translator.translations_for(route) do |locale, translated_name, translated_path, translated_options_constraints, translated_options|
translated_path_ast = ::ActionDispatch::Journey::Parser.parse(translated_path)
translated_mapping = translate_mapping(locale, self, translated_options, translated_path_ast, scope, controller, default_action, to, formatted, via, translated_options_constraints, anchor)
translated_mapping = translate_mapping(locale, self, translated_options, translated_path_ast, scope, controller, default_action, to, formatted, via, translated_options_constraints, anchor, internal)

add_route translated_mapping, translated_name
end
Expand All @@ -24,7 +24,7 @@ def add_localized_route(mapping, name, anchor, scope, path, controller, default_

private

def translate_mapping(locale, route_set, translated_options, translated_path_ast, scope, controller, default_action, to, formatted, via, translated_options_constraints, anchor)
def translate_mapping(locale, route_set, translated_options, translated_path_ast, scope, controller, default_action, to, formatted, via, translated_options_constraints, anchor, internal)
scope_params = {
blocks: (scope[:blocks] || []).dup,
constraints: scope[:constraints] || {},
Expand All @@ -37,7 +37,7 @@ def translate_mapping(locale, route_set, translated_options, translated_path_ast
scope_params[:blocks].push RouteTranslator::Host.lambdas_for_locale(locale)
end

::ActionDispatch::Routing::Mapper::Mapping.build scope_params, route_set, translated_path_ast, controller, default_action, to, via, formatted, translated_options_constraints, anchor, translated_options
::ActionDispatch::Routing::Mapper::Mapping.build scope_params, route_set, translated_path_ast, controller, default_action, to, via, formatted, translated_options_constraints, anchor, internal, translated_options
end
end
end
Expand Down

0 comments on commit 6da3cab

Please sign in to comment.