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.
@@ -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