rackr 0.0.45 → 0.0.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rackr/action.rb +10 -10
- data/lib/rackr/router/build_request.rb +3 -4
- data/lib/rackr/router/route.rb +2 -22
- data/lib/rackr/router.rb +20 -15
- data/lib/rackr.rb +11 -3
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63b5f08cc4a80ac9d5a0ea2a511256242aaf4ed4a243315e6674252f1912888d
|
4
|
+
data.tar.gz: e1e232c9b61919c3d1f34fda5fcb446c2a000c0d2b7330c8b247fe1cf40886d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9356de83cf84a8eda2afdecc1a4d7832b6eb2aa25dc3adfb21a6d979db2eba41e0f92470d1cf26c2f5e4dc8f31deb064c6c4546f8e5df104ba26cec25647f9ef
|
7
|
+
data.tar.gz: 5d474d1584a27200f16876c5da455c5249d66fad31a3c27a4339554285e55270b5e141ddd7d5cec932d479b7952885d71276434e8c160d5fe2b8d7c0fa1d43e7
|
data/lib/rackr/action.rb
CHANGED
@@ -8,10 +8,10 @@ class Rackr
|
|
8
8
|
module Action
|
9
9
|
def self.included(base)
|
10
10
|
base.class_eval do
|
11
|
-
attr_reader :
|
11
|
+
attr_reader :routes, :config, :db if self != Rackr
|
12
12
|
|
13
|
-
def initialize(
|
14
|
-
@
|
13
|
+
def initialize(routes: nil, config: nil)
|
14
|
+
@routes = routes
|
15
15
|
@config = config
|
16
16
|
@db = config[:db]
|
17
17
|
end
|
@@ -22,7 +22,7 @@ class Rackr
|
|
22
22
|
a_view_params,
|
23
23
|
status: status,
|
24
24
|
config: config,
|
25
|
-
|
25
|
+
routes: routes,
|
26
26
|
db: db
|
27
27
|
)
|
28
28
|
end
|
@@ -35,7 +35,7 @@ class Rackr
|
|
35
35
|
a_view_params,
|
36
36
|
status: status,
|
37
37
|
config: config,
|
38
|
-
|
38
|
+
routes: routes,
|
39
39
|
db: db,
|
40
40
|
response_instance: response_instance
|
41
41
|
)
|
@@ -93,7 +93,7 @@ class Rackr
|
|
93
93
|
view_params = {},
|
94
94
|
status: 200,
|
95
95
|
config: {},
|
96
|
-
|
96
|
+
routes: nil,
|
97
97
|
db: nil
|
98
98
|
)
|
99
99
|
view(
|
@@ -101,7 +101,7 @@ class Rackr
|
|
101
101
|
view_params,
|
102
102
|
status: status,
|
103
103
|
config: config,
|
104
|
-
|
104
|
+
routes: routes,
|
105
105
|
db: db,
|
106
106
|
response_instance: true
|
107
107
|
)
|
@@ -112,7 +112,7 @@ class Rackr
|
|
112
112
|
view_params = {},
|
113
113
|
status: 200,
|
114
114
|
config: {},
|
115
|
-
|
115
|
+
routes: nil,
|
116
116
|
db: nil,
|
117
117
|
response_instance: false
|
118
118
|
)
|
@@ -138,7 +138,7 @@ class Rackr
|
|
138
138
|
].join,
|
139
139
|
view_params,
|
140
140
|
config: config,
|
141
|
-
|
141
|
+
routes: routes,
|
142
142
|
db: db
|
143
143
|
)
|
144
144
|
|
@@ -194,7 +194,7 @@ class Rackr
|
|
194
194
|
end
|
195
195
|
|
196
196
|
# rubocop:disable Lint/UnusedMethodArgument
|
197
|
-
def erb(content, view_params = {}, config: nil,
|
197
|
+
def erb(content, view_params = {}, config: nil, routes: nil, db: nil)
|
198
198
|
@view = OpenStruct.new(view_params)
|
199
199
|
|
200
200
|
eval(Erubi::Engine.new(content).src)
|
@@ -3,8 +3,9 @@
|
|
3
3
|
class Rackr
|
4
4
|
class Router
|
5
5
|
class BuildRequest
|
6
|
-
def initialize(env)
|
6
|
+
def initialize(env, spplited_request_path)
|
7
7
|
@env = env
|
8
|
+
@spplited_request_path = spplited_request_path
|
8
9
|
end
|
9
10
|
|
10
11
|
def call(route = nil)
|
@@ -19,14 +20,12 @@ class Rackr
|
|
19
20
|
private
|
20
21
|
|
21
22
|
def update_request_params(request, route)
|
22
|
-
splitted_request_path = request.path.split('/')
|
23
|
-
|
24
23
|
i = 0
|
25
24
|
|
26
25
|
while i < route.splitted_path.size
|
27
26
|
route_word = route.splitted_path[i]
|
28
27
|
if route_word.start_with?(':')
|
29
|
-
param =
|
28
|
+
param = @spplited_request_path[i]
|
30
29
|
param = param.to_i if is_a_integer_string?(param)
|
31
30
|
|
32
31
|
update_request_param(request, route_word, param)
|
data/lib/rackr/router/route.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
class Rackr
|
4
2
|
class Router
|
5
3
|
class Route
|
@@ -21,10 +19,11 @@ class Rackr
|
|
21
19
|
@has_befores = befores != []
|
22
20
|
@afters = afters
|
23
21
|
@has_afters = afters != []
|
22
|
+
@path_regex = /\A#{path.gsub(/(:\w+)/, '([^/]+)')}\z/
|
24
23
|
end
|
25
24
|
|
26
25
|
def match?(env)
|
27
|
-
return
|
26
|
+
return env['PATH_INFO'].match?(@path_regex) if @has_params
|
28
27
|
|
29
28
|
env['PATH_INFO'] == @path
|
30
29
|
end
|
@@ -34,25 +33,6 @@ class Rackr
|
|
34
33
|
def fetch_params
|
35
34
|
@splitted_path.select { |value| value.start_with? ':' }
|
36
35
|
end
|
37
|
-
|
38
|
-
def match_with_params?(env)
|
39
|
-
splitted_request_path = env['PATH_INFO'].split('/')
|
40
|
-
|
41
|
-
return false if @splitted_path.size != splitted_request_path.size
|
42
|
-
|
43
|
-
matched_path_pieces =
|
44
|
-
@splitted_path
|
45
|
-
.map
|
46
|
-
.with_index do |segment, i|
|
47
|
-
if segment.start_with?(':')
|
48
|
-
true
|
49
|
-
else
|
50
|
-
splitted_request_path[i] == segment
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
!matched_path_pieces.include?(false)
|
55
|
-
end
|
56
36
|
end
|
57
37
|
end
|
58
38
|
end
|
data/lib/rackr/router.rb
CHANGED
@@ -7,14 +7,14 @@ require_relative 'router/build_request'
|
|
7
7
|
class Rackr
|
8
8
|
class Router
|
9
9
|
attr_writer :not_found
|
10
|
-
attr_reader :
|
10
|
+
attr_reader :routes, :config
|
11
11
|
|
12
12
|
def initialize(config = {}, before: [], after: [])
|
13
|
-
@
|
13
|
+
@instance_routes = {}
|
14
14
|
%w[GET POST DELETE PUT TRACE OPTIONS PATCH].each do |method|
|
15
|
-
@
|
15
|
+
@instance_routes[method] = { __instances: [] }
|
16
16
|
end
|
17
|
-
@
|
17
|
+
@routes =
|
18
18
|
Hash.new do |_hash, key|
|
19
19
|
raise(Errors::UndefinedNamedRouteError, "Undefined named route: '#{key}'")
|
20
20
|
end
|
@@ -28,10 +28,13 @@ class Rackr
|
|
28
28
|
@branches_named_as = {}
|
29
29
|
@error = proc { |_req, e| raise e }
|
30
30
|
@not_found = proc { [404, {}, ['Not found']] }
|
31
|
+
@splitted_request_path = []
|
31
32
|
end
|
32
33
|
|
33
34
|
def call(env)
|
34
|
-
|
35
|
+
@splitted_request_path = env['PATH_INFO'].split('/')
|
36
|
+
|
37
|
+
request_builder = BuildRequest.new(env, @splitted_request_path)
|
35
38
|
env['REQUEST_METHOD'] = 'GET' if env['REQUEST_METHOD'] == 'HEAD'
|
36
39
|
|
37
40
|
route_instance = match_route(env)
|
@@ -90,7 +93,7 @@ class Rackr
|
|
90
93
|
|
91
94
|
return push_to_branch(method.to_s.upcase, route_instance) if @branches.size >= 1
|
92
95
|
|
93
|
-
@
|
96
|
+
@instance_routes[method.to_s.upcase][:__instances].push(route_instance)
|
94
97
|
end
|
95
98
|
|
96
99
|
def add_not_found(endpoint)
|
@@ -111,6 +114,8 @@ class Rackr
|
|
111
114
|
Errors.check_callbacks(branch_befores, name)
|
112
115
|
Errors.check_callbacks(branch_afters, name)
|
113
116
|
|
117
|
+
name = ":#{name}" if name.is_a? Symbol
|
118
|
+
|
114
119
|
@branches.push(name)
|
115
120
|
|
116
121
|
branch_befores = ensure_array(branch_befores)
|
@@ -138,7 +143,7 @@ class Rackr
|
|
138
143
|
return endpoint.call(content) if endpoint.respond_to?(:call)
|
139
144
|
|
140
145
|
if endpoint.include?(Rackr::Action) || endpoint.include?(Rackr::Callback)
|
141
|
-
return endpoint.new(
|
146
|
+
return endpoint.new(routes: @routes, config: @config).call(content)
|
142
147
|
end
|
143
148
|
|
144
149
|
endpoint.new.call(content)
|
@@ -155,12 +160,12 @@ class Rackr
|
|
155
160
|
nameds_as = [@nameds_as.last].push(as).compact
|
156
161
|
return if nameds_as.empty?
|
157
162
|
|
158
|
-
@
|
163
|
+
@routes[nameds_as.join('_').to_sym] = path_with_branches
|
159
164
|
end
|
160
165
|
|
161
166
|
def push_to_branch(method, route_instance)
|
162
167
|
branches_with_slash = @branches + %i[__instances]
|
163
|
-
push_it(@
|
168
|
+
push_it(@instance_routes[method], *branches_with_slash, route_instance)
|
164
169
|
end
|
165
170
|
|
166
171
|
def push_it(hash, first_key, *rest_keys, val)
|
@@ -186,18 +191,18 @@ class Rackr
|
|
186
191
|
end
|
187
192
|
|
188
193
|
def match_route(env, last_tail = nil, found_branches = [])
|
189
|
-
|
194
|
+
instance_routes =
|
190
195
|
if last_tail.nil?
|
191
|
-
last_tail =
|
196
|
+
last_tail = @splitted_request_path.drop(1)
|
192
197
|
|
193
|
-
@
|
198
|
+
@instance_routes[env['REQUEST_METHOD']]
|
194
199
|
else
|
195
|
-
@
|
200
|
+
@instance_routes[env['REQUEST_METHOD']].dig(*found_branches)
|
196
201
|
end
|
197
202
|
|
198
203
|
segment, *tail = last_tail
|
199
204
|
|
200
|
-
|
205
|
+
instance_routes.each do |branch, _v|
|
201
206
|
next if branch == :__instances
|
202
207
|
|
203
208
|
if segment == branch || branch.start_with?(':')
|
@@ -207,7 +212,7 @@ class Rackr
|
|
207
212
|
end
|
208
213
|
|
209
214
|
if tail.empty? || found_branches == []
|
210
|
-
return @
|
215
|
+
return @instance_routes[env['REQUEST_METHOD']].dig(
|
211
216
|
*(found_branches << :__instances)
|
212
217
|
)
|
213
218
|
&.detect { |route_instance| route_instance.match?(env) }
|
data/lib/rackr.rb
CHANGED
@@ -19,8 +19,8 @@ class Rackr
|
|
19
19
|
@router
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
23
|
-
@router.
|
22
|
+
def routes
|
23
|
+
@router.routes
|
24
24
|
end
|
25
25
|
|
26
26
|
def config
|
@@ -60,7 +60,10 @@ class Rackr
|
|
60
60
|
end
|
61
61
|
|
62
62
|
%w[GET POST DELETE PUT TRACE OPTIONS PATCH].each do |http_method|
|
63
|
-
define_method(http_method.downcase.to_sym) do
|
63
|
+
define_method(http_method.downcase.to_sym) do |*params, as: nil, before: nil, after: nil, &block|
|
64
|
+
path = params[0] || ''
|
65
|
+
endpoint = params[1] || ''
|
66
|
+
|
64
67
|
if block.respond_to?(:call)
|
65
68
|
@router.add(
|
66
69
|
http_method,
|
@@ -71,6 +74,11 @@ class Rackr
|
|
71
74
|
route_afters: after
|
72
75
|
)
|
73
76
|
else
|
77
|
+
if path.is_a?(Module) && path.include?(Action)
|
78
|
+
endpoint = path
|
79
|
+
path = ''
|
80
|
+
end
|
81
|
+
|
74
82
|
@router.add(
|
75
83
|
http_method,
|
76
84
|
path,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rackr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.47
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henrique F. Teixeira
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: erubi
|
@@ -75,7 +75,7 @@ homepage: https://github.com/henrique-ft/rackr
|
|
75
75
|
licenses:
|
76
76
|
- MIT
|
77
77
|
metadata: {}
|
78
|
-
post_install_message:
|
78
|
+
post_install_message:
|
79
79
|
rdoc_options: []
|
80
80
|
require_paths:
|
81
81
|
- lib
|
@@ -90,8 +90,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
90
|
- !ruby/object:Gem::Version
|
91
91
|
version: '0'
|
92
92
|
requirements: []
|
93
|
-
rubygems_version: 3.
|
94
|
-
signing_key:
|
93
|
+
rubygems_version: 3.5.16
|
94
|
+
signing_key:
|
95
95
|
specification_version: 4
|
96
96
|
summary: A complete http router solution that fit well with pure rack apps.
|
97
97
|
test_files: []
|