rackr 0.0.59 → 0.0.61
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/router/errors/dev_html.rb +46 -58
- data/lib/rackr/router.rb +15 -7
- data/lib/rackr.rb +1 -1
- metadata +2 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 958ebe9d9710051bd7966c749bde46693f549b69161f8c2e5fb65df7904defbc
|
4
|
+
data.tar.gz: ce2f52c33670ca35905baad636f541c55d6928dcbdca222fee53e08198f51e62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c54346652bd2b53f1edf2442407c33b443304762e67f368d80d1a98545557c2de26becb6164dc56739c81f5eae680feaf0a5ce09c6476028a4960da390f0fb9
|
7
|
+
data.tar.gz: 2c8f9223a603858d38af27d78ffb3d6123186d3302ab79bc86de33ee87848ffc179f1e6a9bd115db15c6b317c9289eaa165653deaaa881baaab5c236ee99dbc3
|
@@ -1,79 +1,68 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'html_slice'
|
4
|
-
|
5
3
|
class Rackr
|
6
4
|
class Router
|
7
5
|
module Errors
|
8
6
|
class DevHtml
|
9
7
|
include Rackr::Action
|
10
|
-
include ::HtmlSlice
|
11
8
|
|
12
9
|
def call(env)
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
10
|
+
render(html: <<-HTML
|
11
|
+
<!DOCTYPE html>
|
12
|
+
<html>
|
13
|
+
<head>
|
14
|
+
<title>Application error</title>
|
15
|
+
<style>
|
16
|
+
html * { padding:0; margin:0; }
|
17
|
+
body * { padding:10px 20px; }
|
18
|
+
body * * { padding:0; }
|
19
|
+
body { font:small sans-serif; }
|
20
|
+
body>div { border-bottom:1px solid #ddd; }
|
21
|
+
h1 { font-weight:normal; }
|
22
|
+
h2 { margin-bottom:.8em; }
|
23
|
+
h2 span { font-size:80%; color:#666; font-weight:normal; }
|
24
|
+
#summary { background: #ffc; }
|
25
|
+
#summary h2 { font-weight: normal; color: #666; }
|
26
|
+
#backtrace { background: #eee; }
|
27
|
+
pre {
|
28
|
+
background: #ddd;
|
29
|
+
padding: 1em;
|
30
|
+
margin-bottom: 1em;
|
31
|
+
}
|
32
|
+
p {
|
33
|
+
font-family: monospace;
|
34
|
+
}
|
35
|
+
</style>
|
36
|
+
</head>
|
37
|
+
<body>
|
38
|
+
<div id="summary">
|
39
|
+
<h1>#{env['error'].class}</h1>
|
40
|
+
<h2>#{env['error'].message.size > 1000 ? "#{env['error'].message.slice(0, 1000)} ..." : env['error'].message}</h2>
|
41
|
+
</div>
|
42
|
+
<div id="backtrace">
|
43
|
+
#{backtrace(env)}
|
44
|
+
</div>
|
45
|
+
</body>
|
46
|
+
</html>
|
47
|
+
HTML
|
48
|
+
)
|
48
49
|
end
|
49
50
|
|
50
51
|
def backtrace(env)
|
51
52
|
first, *tail = env['error'].backtrace
|
52
|
-
h2
|
53
|
-
|
54
|
-
span '(innermost first)'
|
55
|
-
end
|
56
|
-
|
57
|
-
tag :p, first, class: 'first-p'
|
58
|
-
br
|
53
|
+
traceback = String.new("<h2>Traceback <span>(innermost first)</span></h2>")
|
54
|
+
traceback << "<p class=\"first-p\">#{first}</p><br/>"
|
59
55
|
|
60
56
|
line_number = extract_line_number(first)
|
61
|
-
match = first.match(%r{^(/[\w/.-]+)})
|
57
|
+
match = first.match(%r{^(/[[\w/.-]]+)})
|
62
58
|
file_path = (match ? match[1] : nil)
|
63
59
|
unless file_path.nil?
|
64
|
-
lines =
|
65
|
-
|
66
|
-
lines = file.readlines
|
67
|
-
end
|
68
|
-
|
69
|
-
lines.map!.with_index do |line, i|
|
70
|
-
"#{i + 1}: #{line} \n"
|
71
|
-
end
|
72
|
-
|
73
|
-
tag :pre, slice_around_index(lines, line_number).join('').chomp
|
60
|
+
lines = File.readlines(file_path).map.with_index { |line, i| "#{i + 1}: #{line}" }
|
61
|
+
traceback << "<pre>#{slice_around_index(lines, line_number).join('')}</pre>"
|
74
62
|
end
|
75
63
|
|
76
|
-
|
64
|
+
traceback << "<p>#{tail.join("<br>")}</p>"
|
65
|
+
traceback
|
77
66
|
end
|
78
67
|
|
79
68
|
def extract_line_number(input)
|
@@ -89,7 +78,6 @@ class Rackr
|
|
89
78
|
start_index = [index - 2, 0].max
|
90
79
|
end_index = [index + 2, array.size - 1].min
|
91
80
|
|
92
|
-
# Slice the array
|
93
81
|
array[start_index..end_index]
|
94
82
|
end
|
95
83
|
end
|
data/lib/rackr/router.rb
CHANGED
@@ -200,6 +200,12 @@ class Rackr
|
|
200
200
|
end
|
201
201
|
|
202
202
|
def match_route(request_method)
|
203
|
+
find_instance_in_scope = proc do |request_method, found_scopes|
|
204
|
+
@instance_routes[request_method].dig(
|
205
|
+
*(found_scopes + [:__instances])
|
206
|
+
)&.detect { |route_instance| route_instance.match?(@current_request_path_info) }
|
207
|
+
end
|
208
|
+
|
203
209
|
last_tail = @splitted_request_path_info.drop(1)
|
204
210
|
found_scopes = []
|
205
211
|
|
@@ -217,10 +223,7 @@ class Rackr
|
|
217
223
|
instance_routes = @instance_routes[request_method].dig(*found_scopes)
|
218
224
|
break
|
219
225
|
elsif scope.start_with?(':')
|
220
|
-
found_route =
|
221
|
-
*(found_scopes + [:__instances])
|
222
|
-
)&.detect { |route_instance| route_instance.match?(@current_request_path_info) }
|
223
|
-
|
226
|
+
found_route = find_instance_in_scope.(request_method, found_scopes)
|
224
227
|
return found_route if found_route
|
225
228
|
|
226
229
|
found_scopes << scope
|
@@ -230,9 +233,14 @@ class Rackr
|
|
230
233
|
end
|
231
234
|
end
|
232
235
|
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
+
result_route = find_instance_in_scope.(request_method, found_scopes)
|
237
|
+
|
238
|
+
if result_route == nil && !found_scopes.empty?
|
239
|
+
found_scopes.shift
|
240
|
+
result_route = find_instance_in_scope.(request_method, found_scopes)
|
241
|
+
end
|
242
|
+
|
243
|
+
result_route
|
236
244
|
end
|
237
245
|
end
|
238
246
|
end
|
data/lib/rackr.rb
CHANGED
@@ -66,7 +66,7 @@ class Rackr
|
|
66
66
|
const_name = name.to_s.capitalize
|
67
67
|
id ||= :id
|
68
68
|
|
69
|
-
scope name do
|
69
|
+
scope name.to_s do
|
70
70
|
get Object.const_get("Actions::#{const_name}::Index") if Object.const_defined?("Actions::#{const_name}::Index")
|
71
71
|
get 'new', Object.const_get("Actions::#{const_name}::New") if Object.const_defined?("Actions::#{const_name}::New")
|
72
72
|
post Object.const_get("Actions::#{const_name}::Index") if Object.const_defined?("Actions::#{const_name}::Index")
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
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.61
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henrique F. Teixeira
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-10-12 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: erubi
|
@@ -57,26 +57,6 @@ dependencies:
|
|
57
57
|
- - "<"
|
58
58
|
- !ruby/object:Gem::Version
|
59
59
|
version: '4.0'
|
60
|
-
- !ruby/object:Gem::Dependency
|
61
|
-
name: html_slice
|
62
|
-
requirement: !ruby/object:Gem::Requirement
|
63
|
-
requirements:
|
64
|
-
- - ">="
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
version: '0.0'
|
67
|
-
- - "<"
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: '1.0'
|
70
|
-
type: :runtime
|
71
|
-
prerelease: false
|
72
|
-
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
requirements:
|
74
|
-
- - ">="
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
version: '0.0'
|
77
|
-
- - "<"
|
78
|
-
- !ruby/object:Gem::Version
|
79
|
-
version: '1.0'
|
80
60
|
description: A complete, simple and easy web micro-framework.
|
81
61
|
email: hriqueft@gmail.com
|
82
62
|
executables: []
|