sinatra-router 0.2.4 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/sinatra/router.rb +21 -13
- metadata +9 -57
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7bdad888992cc1c5950f07d56c1e4ce4a82a95cbccc43d7c569ff68f451f13e4
|
4
|
+
data.tar.gz: 4d567cac837af1540df8eda8dd4cf72fa38f6b2d359925e8a25def3aef1970e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9d763ceebf1574b6d50f0a62bb30b9a206c800f576dce8d6035ad17a0276ec159b5b91dc0ce13e306582031303c5b4331169d9bf6244f993204c5a4708d4bab
|
7
|
+
data.tar.gz: 94bc10e31d562f38df0e0f52999f0a5e92de2f299223af3f2069422784a66a97f8a72d041624c85c93ece687032260a5795785598eaa7f5bb2c3b720c2b34b54
|
data/lib/sinatra/router.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Sinatra
|
4
|
+
# A Sinatra router that allows multiple Sinatra applications to be composed
|
5
|
+
# together.
|
2
6
|
class Router
|
3
|
-
def initialize(app=nil, *
|
7
|
+
def initialize(app = nil, *_args, &block)
|
4
8
|
@app = app
|
5
9
|
@apps = []
|
6
10
|
@conditions = []
|
@@ -11,11 +15,13 @@ module Sinatra
|
|
11
15
|
end
|
12
16
|
|
13
17
|
def call(env)
|
14
|
-
if ret = try_route(env[
|
18
|
+
if (ret = try_route(env['REQUEST_METHOD'], env['PATH_INFO'], env))
|
15
19
|
ret
|
16
20
|
else
|
17
|
-
|
18
|
-
|
21
|
+
if !@app && !@run
|
22
|
+
raise 'router needs to be (1) mounted as middleware or (b) contain ' \
|
23
|
+
'a default run statement'
|
24
|
+
end
|
19
25
|
|
20
26
|
# if set as middlware, prefer that, otherwise try default run module
|
21
27
|
(@app || @run).call(env)
|
@@ -24,7 +30,8 @@ module Sinatra
|
|
24
30
|
|
25
31
|
# specify the default app to run if no other app routes matched
|
26
32
|
def run(app)
|
27
|
-
raise
|
33
|
+
raise '@run already set' if @run
|
34
|
+
|
28
35
|
@run = app
|
29
36
|
end
|
30
37
|
|
@@ -45,7 +52,7 @@ module Sinatra
|
|
45
52
|
|
46
53
|
def with_conditions(*args, &block)
|
47
54
|
old = @conditions
|
48
|
-
@conditions
|
55
|
+
@conditions += args
|
49
56
|
instance_eval(&block) if block
|
50
57
|
@conditions = old
|
51
58
|
end
|
@@ -56,6 +63,7 @@ module Sinatra
|
|
56
63
|
all_routes = {}
|
57
64
|
@apps.each do |app, conditions|
|
58
65
|
next unless app.respond_to?(:routes)
|
66
|
+
|
59
67
|
app.routes.each do |verb, routes|
|
60
68
|
all_routes[verb] ||= []
|
61
69
|
all_routes[verb] += routes.map do |pattern, _, _, _|
|
@@ -75,16 +83,16 @@ module Sinatra
|
|
75
83
|
|
76
84
|
def try_route(verb, path, env)
|
77
85
|
# see Sinatra's `route!`
|
78
|
-
if verb_routes = @routes[verb]
|
86
|
+
if (verb_routes = @routes[verb])
|
79
87
|
verb_routes.each do |pattern, conditions, app|
|
80
|
-
if pattern.match(path)
|
81
|
-
status, headers, response = app.call(env)
|
88
|
+
next if !pattern.match(path) || !conditions_match?(conditions, env)
|
82
89
|
|
83
|
-
|
84
|
-
next if headers["X-Cascade"] == "pass"
|
90
|
+
status, headers, response = app.call(env)
|
85
91
|
|
86
|
-
|
87
|
-
|
92
|
+
# if we got a pass, keep trying routes
|
93
|
+
next if headers['X-Cascade'] == 'pass'
|
94
|
+
|
95
|
+
return status, headers, response
|
88
96
|
end
|
89
97
|
end
|
90
98
|
nil
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-router
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandur
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -17,9 +17,6 @@ dependencies:
|
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.4'
|
20
|
-
- - "<"
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: '3.0'
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -27,52 +24,7 @@ dependencies:
|
|
27
24
|
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '1.4'
|
30
|
-
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: '3.0'
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: minitest
|
35
|
-
requirement: !ruby/object:Gem::Requirement
|
36
|
-
requirements:
|
37
|
-
- - ">="
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
version: '0'
|
40
|
-
type: :development
|
41
|
-
prerelease: false
|
42
|
-
version_requirements: !ruby/object:Gem::Requirement
|
43
|
-
requirements:
|
44
|
-
- - ">="
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: '0'
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: rack-test
|
49
|
-
requirement: !ruby/object:Gem::Requirement
|
50
|
-
requirements:
|
51
|
-
- - ">="
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '0'
|
54
|
-
type: :development
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
requirements:
|
58
|
-
- - ">="
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version: '0'
|
61
|
-
- !ruby/object:Gem::Dependency
|
62
|
-
name: rake
|
63
|
-
requirement: !ruby/object:Gem::Requirement
|
64
|
-
requirements:
|
65
|
-
- - ">="
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version: '0'
|
68
|
-
type: :development
|
69
|
-
prerelease: false
|
70
|
-
version_requirements: !ruby/object:Gem::Requirement
|
71
|
-
requirements:
|
72
|
-
- - ">="
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
version: '0'
|
75
|
-
description:
|
27
|
+
description:
|
76
28
|
email: brandur@mutelight.org
|
77
29
|
executables: []
|
78
30
|
extensions: []
|
@@ -82,8 +34,9 @@ files:
|
|
82
34
|
homepage: https://github.com/brandur/sinatra-router
|
83
35
|
licenses:
|
84
36
|
- MIT
|
85
|
-
metadata:
|
86
|
-
|
37
|
+
metadata:
|
38
|
+
rubygems_mfa_required: 'true'
|
39
|
+
post_install_message:
|
87
40
|
rdoc_options: []
|
88
41
|
require_paths:
|
89
42
|
- lib
|
@@ -98,9 +51,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
51
|
- !ruby/object:Gem::Version
|
99
52
|
version: '0'
|
100
53
|
requirements: []
|
101
|
-
|
102
|
-
|
103
|
-
signing_key:
|
54
|
+
rubygems_version: 3.4.6
|
55
|
+
signing_key:
|
104
56
|
specification_version: 4
|
105
57
|
summary: A tiny vendorable router that makes it easy to try routes from a number of
|
106
58
|
different modular Sinatra applications.
|