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.
Files changed (3) hide show
  1. checksums.yaml +5 -5
  2. data/lib/sinatra/router.rb +21 -13
  3. metadata +9 -57
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: 7bdad888992cc1c5950f07d56c1e4ce4a82a95cbccc43d7c569ff68f451f13e4
4
+ data.tar.gz: 4d567cac837af1540df8eda8dd4cf72fa38f6b2d359925e8a25def3aef1970e6
5
5
  SHA512:
6
- metadata.gz: 08d376d6f5eb2f90ce76a4b03073820f662b2a0914c360b2fcbba2c817608847a41eb7d3a19c716a2ec4b899af8fe1ca3f4af174a2f5483204a9fcc62d24ddd8
7
- data.tar.gz: f611d3dad232c3c9814b63021880f9dff0232fa1d8c9f76edfd281691e0b22a8c08e6120c366afd0b0b61c17bd412a143882e2ea2c34052c314a798a19274dcf
6
+ metadata.gz: d9d763ceebf1574b6d50f0a62bb30b9a206c800f576dce8d6035ad17a0276ec159b5b91dc0ce13e306582031303c5b4331169d9bf6244f993204c5a4708d4bab
7
+ data.tar.gz: 94bc10e31d562f38df0e0f52999f0a5e92de2f299223af3f2069422784a66a97f8a72d041624c85c93ece687032260a5795785598eaa7f5bb2c3b720c2b34b54
@@ -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.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: 2017-05-17 00:00:00.000000000 Z
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
- post_install_message:
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
- rubyforge_project:
102
- rubygems_version: 2.5.1
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.