ratalada-contrib 3.1.1 → 4.0.0
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 26dba7a38ccd7122419ea2e6def4232323dd5ca54301b126ec6dfaef35abc11f
|
|
4
|
+
data.tar.gz: 178d77411ea26d9a93cb33e16c85a508b38212e1ce8473584cc2d243da3710fb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ac1d4bfad931f87ebfb73819c2e50c7ee07a3333bc10f3341d024dd0f433d678dd7c648b28b6788deb4742a0eb40c3ca05f6b392ebeb6cf8702c3b897c6c2a98
|
|
7
|
+
data.tar.gz: e5c22ee039ac699a1e9702964c7efeed34bb1eb9e75e3d093d0f7130c12cc1f8ecb03026976024c95372875aad602789390551555e80c48473500bfb0c93ee86
|
|
@@ -21,6 +21,34 @@ module Ratalada
|
|
|
21
21
|
|
|
22
22
|
def route_spelling = SPELLING
|
|
23
23
|
|
|
24
|
+
# ONE APP PER ROUTE FILE, NOT ONE FOR THE TREE. `use`, `set`, `before`,
|
|
25
|
+
# `error` and `helpers` are all class-level Sinatra DSL, so evaluating
|
|
26
|
+
# every file into a single Sinatra::Base makes a _layout.rb reach files
|
|
27
|
+
# it does not sit above: an app/(api)/_layout.rb with
|
|
28
|
+
# `before { content_type(:json) }` relabels every HTML page in the tree.
|
|
29
|
+
# A layout is meant to scope those to its own subtree, which it can only
|
|
30
|
+
# do if the files under it have a class of their own.
|
|
31
|
+
#
|
|
32
|
+
# So each route file (with the layouts above it) becomes its own
|
|
33
|
+
# subclass, and they are chained: a Sinatra app used as rack middleware
|
|
34
|
+
# forwards the request on when none of its own routes matched
|
|
35
|
+
# (Base#route_missing), so the first file that spells the path answers
|
|
36
|
+
# and the rest fall through. build_map already orders them
|
|
37
|
+
# most-specific-first.
|
|
38
|
+
#
|
|
39
|
+
# ponytail: one middleware hop per route file, walked per request.
|
|
40
|
+
# Collapse the leaves into one class if a fat tree ever shows up in a
|
|
41
|
+
# profile -- the isolation is the point, not the chain.
|
|
42
|
+
def mount_files(parent, map)
|
|
43
|
+
map.each do |prefix, paths|
|
|
44
|
+
child = Class.new(::Sinatra::Base)
|
|
45
|
+
child.route_prefix = prefix
|
|
46
|
+
paths.each { |path| child.class_eval(File.read(path), path, 1) }
|
|
47
|
+
|
|
48
|
+
parent.use(child)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
24
52
|
def route(verb, path, options = {}, &block)
|
|
25
53
|
unless route_prefix.to_s.empty?
|
|
26
54
|
path = Mustermann.new(FileBased.join(route_prefix, path), type: :expo)
|
|
@@ -28,9 +28,19 @@ module Ratalada
|
|
|
28
28
|
spelling = {}
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
build_map(directory, **spelling)
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
map = build_map(directory, **spelling)
|
|
32
|
+
|
|
33
|
+
# An adapter that can give each route file its own class does, so a
|
|
34
|
+
# _layout.rb's `use`, `set`, `before` and `error` reach only the files
|
|
35
|
+
# below it. Without that the whole tree shares one class and a nested
|
|
36
|
+
# layout's filter fires for every route in the app.
|
|
37
|
+
if app.respond_to?(:mount_files)
|
|
38
|
+
app.mount_files(app, map)
|
|
39
|
+
else
|
|
40
|
+
map.each do |prefix, paths|
|
|
41
|
+
app.route_prefix = prefix
|
|
42
|
+
paths.each { |path| app.class_eval(File.read(path), path, 1) }
|
|
43
|
+
end
|
|
34
44
|
end
|
|
35
45
|
end
|
|
36
46
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ratalada-contrib
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 4.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nathan K
|
|
@@ -15,14 +15,14 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - "~>"
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: '
|
|
18
|
+
version: '4.0'
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - "~>"
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: '
|
|
25
|
+
version: '4.0'
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
27
|
name: mustermann
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|