sinatra-router 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +5 -5
  2. data/lib/sinatra/router.rb +21 -13
  3. metadata +11 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 89e770f9cecfaa6f9ef8ee2c03928c683679ef29
4
- data.tar.gz: 5ea0e147dd53d872a318e81a3e393e3e329d01f2
2
+ SHA256:
3
+ metadata.gz: c9a8de0d20079516830e1f738a4d10b98af59bc4c2ac1adb235654d7d1c3fe0a
4
+ data.tar.gz: 777c676fa17f2d5d9fc9ba5e513a414a211970c7e3559b7a83cd2ec569a4d8d0
5
5
  SHA512:
6
- metadata.gz: 08d376d6f5eb2f90ce76a4b03073820f662b2a0914c360b2fcbba2c817608847a41eb7d3a19c716a2ec4b899af8fe1ca3f4af174a2f5483204a9fcc62d24ddd8
7
- data.tar.gz: f611d3dad232c3c9814b63021880f9dff0232fa1d8c9f76edfd281691e0b22a8c08e6120c366afd0b0b61c17bd412a143882e2ea2c34052c314a798a19274dcf
6
+ metadata.gz: 6f54da7b5cae76cde89c4f221b459bd26bf6e6674011d8ff83b08d313ef1ec66654ce98408c07c309198eac864273e83f18f60e2f2be03abb55131b5f98778f3
7
+ data.tar.gz: 70709147b865e2c929c7b16726b8b18ce2cfaca3a57b80c4646c4cf9b37ef8c78a07433a1b9cff55bcf675667084338c092c0ecbf869d2a4ef43e3f1f977a210
@@ -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, *args, &block)
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["REQUEST_METHOD"], env["PATH_INFO"], env)
18
+ if (ret = try_route(env['REQUEST_METHOD'], env['PATH_INFO'], env))
15
19
  ret
16
20
  else
17
- raise "router needs to be (1) mounted as middleware or (b) contain " +
18
- "a default run statement" if !@app && !@run
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 "@run already set" if @run
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 = @conditions + args
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) && conditions_match?(conditions, env)
81
- status, headers, response = app.call(env)
88
+ next if !pattern.match(path) || !conditions_match?(conditions, env)
82
89
 
83
- # if we got a pass, keep trying routes
84
- next if headers["X-Cascade"] == "pass"
90
+ status, headers, response = app.call(env)
85
91
 
86
- return status, headers, response
87
- end
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.2.4
4
+ version: 0.3.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: 2017-05-17 00:00:00.000000000 Z
11
+ date: 2022-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '1.4'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '3.0'
22
+ version: '4.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '1.4'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '3.0'
32
+ version: '4.0'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: minitest
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -72,7 +72,7 @@ dependencies:
72
72
  - - ">="
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
- description:
75
+ description:
76
76
  email: brandur@mutelight.org
77
77
  executables: []
78
78
  extensions: []
@@ -82,8 +82,9 @@ files:
82
82
  homepage: https://github.com/brandur/sinatra-router
83
83
  licenses:
84
84
  - MIT
85
- metadata: {}
86
- post_install_message:
85
+ metadata:
86
+ rubygems_mfa_required: 'true'
87
+ post_install_message:
87
88
  rdoc_options: []
88
89
  require_paths:
89
90
  - lib
@@ -98,9 +99,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
99
  - !ruby/object:Gem::Version
99
100
  version: '0'
100
101
  requirements: []
101
- rubyforge_project:
102
- rubygems_version: 2.5.1
103
- signing_key:
102
+ rubygems_version: 3.3.7
103
+ signing_key:
104
104
  specification_version: 4
105
105
  summary: A tiny vendorable router that makes it easy to try routes from a number of
106
106
  different modular Sinatra applications.