Skip to content

Commit 376bc8e

Browse files
committed
Use scope for cleaner solution
1 parent 3e622fc commit 376bc8e

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

lib/patches/mapper.rb

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,22 @@ module InertiaMapper
33
def inertia(*args, **options)
44
path = args.any? ? args.first : options
55
route, component = extract_route_and_component(path)
6-
@scope = @scope.new(module: nil)
7-
get(route, to: 'inertia_rails/static#static', defaults: { component: component }, **options)
8-
ensure
9-
@scope = @scope.parent
6+
scope module: nil do
7+
get(route, to: 'inertia_rails/static#static', defaults: { component: component }, **options)
8+
end
109
end
1110

1211
private
1312

14-
def extract_route_and_component(args)
15-
if args.is_a?(Hash)
16-
args.first
13+
def extract_route_and_component(path)
14+
if path.is_a?(Hash)
15+
path.first
1716
elsif resource_scope?
18-
[args, InertiaRails.configuration.component_path_resolver(path: [@scope[:module], @scope[:controller]].compact.join('/'), action: args)]
17+
[path, InertiaRails.configuration.component_path_resolver(path: [@scope[:module], @scope[:controller]].compact.join('/'), action: path)]
1918
elsif @scope[:module].blank?
20-
[args, args]
19+
[path, path]
2120
else
22-
[args, InertiaRails.configuration.component_path_resolver(path: @scope[:module], action: args)]
21+
[path, InertiaRails.configuration.component_path_resolver(path: @scope[:module], action: path)]
2322
end
2423
end
2524
end

0 commit comments

Comments
 (0)