hanami-router 2.0.0.alpha1 → 2.0.0.alpha2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/README.md +11 -401
- data/hanami-router.gemspec +2 -4
- data/lib/hanami/middleware/body_parser.rb +2 -2
- data/lib/hanami/middleware/body_parser/class_interface.rb +10 -4
- data/lib/hanami/middleware/body_parser/json_parser.rb +4 -4
- data/lib/hanami/router.rb +525 -1040
- data/lib/hanami/router/block.rb +88 -0
- data/lib/hanami/router/error.rb +67 -0
- data/lib/hanami/router/node.rb +93 -0
- data/lib/hanami/router/params.rb +35 -0
- data/lib/hanami/router/prefix.rb +65 -0
- data/lib/hanami/router/recognized_route.rb +92 -0
- data/lib/hanami/router/redirect.rb +28 -0
- data/lib/hanami/router/segment.rb +19 -0
- data/lib/hanami/router/trie.rb +63 -0
- data/lib/hanami/router/url_helpers.rb +40 -0
- data/lib/hanami/router/version.rb +2 -1
- metadata +17 -48
- data/lib/hanami/routing.rb +0 -193
- data/lib/hanami/routing/endpoint.rb +0 -213
- data/lib/hanami/routing/endpoint_resolver.rb +0 -242
- data/lib/hanami/routing/prefix.rb +0 -102
- data/lib/hanami/routing/recognized_route.rb +0 -233
- data/lib/hanami/routing/resource.rb +0 -121
- data/lib/hanami/routing/resource/action.rb +0 -427
- data/lib/hanami/routing/resource/nested.rb +0 -44
- data/lib/hanami/routing/resource/options.rb +0 -76
- data/lib/hanami/routing/resources.rb +0 -50
- data/lib/hanami/routing/resources/action.rb +0 -161
- data/lib/hanami/routing/routes_inspector.rb +0 -223
- data/lib/hanami/routing/scope.rb +0 -112
data/lib/hanami/routing/scope.rb
DELETED
@@ -1,112 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "delegate"
|
4
|
-
require "hanami/utils/path_prefix"
|
5
|
-
|
6
|
-
module Hanami
|
7
|
-
module Routing
|
8
|
-
# Prefix for routes.
|
9
|
-
# Implementation of Hanami::Router#prefix
|
10
|
-
#
|
11
|
-
# @since 2.0.0
|
12
|
-
# @api private
|
13
|
-
#
|
14
|
-
# @see Hanami::Router#prefix
|
15
|
-
class Scope < SimpleDelegator
|
16
|
-
# @api private
|
17
|
-
# @since 2.0.0
|
18
|
-
def initialize(router, prefix, namespace, configuration, &blk)
|
19
|
-
@router = router
|
20
|
-
@namespace = namespace
|
21
|
-
@configuration = configuration
|
22
|
-
@prefix = Utils::PathPrefix.new(prefix)
|
23
|
-
__setobj__(@router)
|
24
|
-
instance_eval(&blk)
|
25
|
-
end
|
26
|
-
|
27
|
-
def root(to:, as: :root, **, &blk)
|
28
|
-
super(to: to, as: route_name(as), prefix: @prefix, namespace: @namespace, configuration: @configuration, &blk)
|
29
|
-
end
|
30
|
-
|
31
|
-
# @api private
|
32
|
-
# @since 2.0.0
|
33
|
-
def get(path, as: nil, **options, &endpoint)
|
34
|
-
super(@prefix.join(path), options.merge(as: route_name(as), namespace: @namespace, configuration: @configuration), &endpoint)
|
35
|
-
end
|
36
|
-
|
37
|
-
# @api private
|
38
|
-
# @since 2.0.0
|
39
|
-
def post(path, as: nil, **options, &endpoint)
|
40
|
-
super(@prefix.join(path), options.merge(as: route_name(as), namespace: @namespace, configuration: @configuration), &endpoint)
|
41
|
-
end
|
42
|
-
|
43
|
-
# @api private
|
44
|
-
# @since 2.0.0
|
45
|
-
def put(path, as: nil, **options, &endpoint)
|
46
|
-
super(@prefix.join(path), options.merge(as: route_name(as), namespace: @namespace, configuration: @configuration), &endpoint)
|
47
|
-
end
|
48
|
-
|
49
|
-
# @api private
|
50
|
-
# @since 2.0.0
|
51
|
-
def patch(path, as: nil, **options, &endpoint)
|
52
|
-
super(@prefix.join(path), options.merge(as: route_name(as), namespace: @namespace, configuration: @configuration), &endpoint)
|
53
|
-
end
|
54
|
-
|
55
|
-
# @api private
|
56
|
-
# @since 2.0.0
|
57
|
-
def delete(path, as: nil, **options, &endpoint)
|
58
|
-
super(@prefix.join(path), options.merge(as: route_name(as), namespace: @namespace, configuration: @configuration), &endpoint)
|
59
|
-
end
|
60
|
-
|
61
|
-
# @api private
|
62
|
-
# @since 2.0.0
|
63
|
-
def trace(path, as: nil, **options, &endpoint)
|
64
|
-
super(@prefix.join(path), options.merge(as: route_name(as), namespace: @namespace, configuration: @configuration), &endpoint)
|
65
|
-
end
|
66
|
-
|
67
|
-
# @api private
|
68
|
-
# @since 2.0.0
|
69
|
-
def options(path, as: nil, **options, &endpoint)
|
70
|
-
super(@prefix.join(path), options.merge(as: route_name(as), namespace: @namespace, configuration: @configuration), &endpoint)
|
71
|
-
end
|
72
|
-
|
73
|
-
# @api private
|
74
|
-
# @since 2.0.0
|
75
|
-
def resource(name, options = {})
|
76
|
-
super(name, options.merge(prefix: @prefix.relative_join(options[:prefix]), namespace: @namespace, configuration: @configuration))
|
77
|
-
end
|
78
|
-
|
79
|
-
# @api private
|
80
|
-
# @since 2.0.0
|
81
|
-
def resources(name, options = {})
|
82
|
-
super(name, options.merge(prefix: @prefix.relative_join(options[:prefix]), namespace: @namespace, configuration: @configuration))
|
83
|
-
end
|
84
|
-
|
85
|
-
# @api private
|
86
|
-
# @since 2.0.0
|
87
|
-
def redirect(path, options = {}, &endpoint)
|
88
|
-
super(@prefix.join(path), options.merge(to: @prefix.join(options[:to])), &endpoint)
|
89
|
-
end
|
90
|
-
|
91
|
-
# @api private
|
92
|
-
# @since 2.0.0
|
93
|
-
def mount(app, options)
|
94
|
-
super(app, options.merge(at: @prefix.join(options[:at])))
|
95
|
-
end
|
96
|
-
|
97
|
-
# @api private
|
98
|
-
# @since 2.0.0
|
99
|
-
def prefix(path, &blk)
|
100
|
-
super(@prefix.join(path), namespace: @namespace, configuration: @configuration, &blk)
|
101
|
-
end
|
102
|
-
|
103
|
-
private
|
104
|
-
|
105
|
-
ROUTE_NAME_SEPARATOR = "_"
|
106
|
-
|
107
|
-
def route_name(as)
|
108
|
-
@prefix.relative_join(as, ROUTE_NAME_SEPARATOR).to_sym unless as.nil?
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|