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