rutter 0.2.0 → 0.3.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 +4 -4
- data/.rubocop.yml +5 -9
- data/.travis.yml +3 -8
- data/Gemfile +3 -3
- data/LICENSE.txt +1 -1
- data/README.md +2 -6
- data/lib/rutter/builder.rb +7 -5
- data/lib/rutter/mount.rb +24 -0
- data/lib/rutter/routes.rb +3 -2
- data/lib/rutter/scope.rb +2 -2
- data/lib/rutter/version.rb +1 -1
- data/spec/integration/rack_spec.rb +0 -2
- data/spec/spec_helper.rb +5 -4
- data/spec/unit/builder_spec.rb +17 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12a5714cb11c9589f34960ce325c4a095f4d5c8dbeb15d95e8f9b9be560d15d8
|
4
|
+
data.tar.gz: f182eb9db7eb3205a003379fd937864e2dda69b615be63e37ad4cfbc8a523402
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0885bcb1e09323e8d3e4753a04a2fd192d726c68d4546ba820fa29ae9d9492c847c296022b6e34cb4123808fa87633c5728b2042467d0e1e79ec1d9b679b200a'
|
7
|
+
data.tar.gz: 928d8dfd4b82989f196f0a0f25fcf734953c8b77f0884697f756382117de1aaa51f7049e832dc627d1a6dabea43143046ebf08e4e842497a899bd253cee45372
|
data/.rubocop.yml
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
require:
|
2
|
-
- rubocop-performance
|
3
|
-
|
1
|
+
require: rubocop-performance
|
4
2
|
AllCops:
|
5
3
|
TargetRubyVersion: 2.5
|
4
|
+
NewCops: enable
|
6
5
|
DisplayCopNames: true
|
7
6
|
Exclude:
|
8
7
|
- "*.gemspec"
|
@@ -14,6 +13,9 @@ Performance:
|
|
14
13
|
Style/StringLiterals:
|
15
14
|
EnforcedStyle: double_quotes
|
16
15
|
|
16
|
+
Style/ClassAndModuleChildren:
|
17
|
+
Enabled: false
|
18
|
+
|
17
19
|
Layout/EmptyLineAfterGuardClause:
|
18
20
|
Enabled: false
|
19
21
|
|
@@ -27,9 +29,3 @@ Metrics/BlockLength:
|
|
27
29
|
Metrics/ModuleLength:
|
28
30
|
Exclude:
|
29
31
|
- "spec/**/*"
|
30
|
-
|
31
|
-
ClassAndModuleChildren:
|
32
|
-
Enabled: false
|
33
|
-
|
34
|
-
Naming/UncommunicativeMethodParamName:
|
35
|
-
MinNameLength: 2
|
data/.travis.yml
CHANGED
@@ -3,20 +3,15 @@ script: "bundle exec rake spec:coverage"
|
|
3
3
|
cache: bundler
|
4
4
|
env:
|
5
5
|
global:
|
6
|
-
-
|
6
|
+
- CODECOV_TOKEN="21653af2-874b-4597-942d-14ddc7c2f8fa"
|
7
7
|
before_install:
|
8
8
|
- "gem update --system"
|
9
|
-
before_script:
|
10
|
-
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
11
|
-
- chmod +x ./cc-test-reporter
|
12
|
-
- ./cc-test-reporter before-build
|
13
|
-
after_script:
|
14
|
-
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
15
9
|
rvm:
|
10
|
+
- 2.7.0
|
16
11
|
- 2.6.0
|
17
12
|
- 2.5.0
|
18
|
-
- jruby-9.2.0.0
|
19
13
|
- ruby-head
|
14
|
+
- jruby
|
20
15
|
- jruby-head
|
21
16
|
- truffleruby
|
22
17
|
matrix:
|
data/Gemfile
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,13 +1,9 @@
|
|
1
1
|
# Rutter
|
2
2
|
|
3
|
-
HTTP router for Rack.
|
4
|
-
|
5
|
-
## Status
|
6
|
-
|
7
|
-
Under development, not ready for prime-time just yet.
|
3
|
+
HTTP router for Ramverk and Rack.
|
8
4
|
|
9
5
|
[](https://travis-ci.org/sandelius/rutter)
|
10
|
-
[](https://codecov.io/gh/sandelius/rutter)
|
11
7
|
[](http://inch-ci.org/github/sandelius/rutter)
|
12
8
|
|
13
9
|
## Installation
|
data/lib/rutter/builder.rb
CHANGED
@@ -91,10 +91,12 @@ module Rutter
|
|
91
91
|
# Application to mount.
|
92
92
|
# @param at [String]
|
93
93
|
# Path prefix to match.
|
94
|
+
# @param host [Regexp]
|
95
|
+
# Match the given host pattern.
|
94
96
|
#
|
95
97
|
# @return [Rutter::Mount]
|
96
|
-
def mount(app, at:)
|
97
|
-
route = Mount.new(at, app)
|
98
|
+
def mount(app, at:, host: nil)
|
99
|
+
route = Mount.new(at, app, host: host)
|
98
100
|
@flat_map << route
|
99
101
|
VERBS.each { |verb| @verb_map[verb] << route }
|
100
102
|
route
|
@@ -131,12 +133,12 @@ module Rutter
|
|
131
133
|
# # => "/login?return_to=/"
|
132
134
|
# router.path(:book, id: 82)
|
133
135
|
# # => "/books/82"
|
134
|
-
def path(name,
|
136
|
+
def path(name, **args)
|
135
137
|
unless (route = @named_map[name])
|
136
138
|
raise "No route called '#{name}' was found"
|
137
139
|
end
|
138
140
|
|
139
|
-
route.expand(
|
141
|
+
route.expand(**args)
|
140
142
|
end
|
141
143
|
|
142
144
|
# Generates a full URL from the given arguments.
|
@@ -178,7 +180,7 @@ module Rutter
|
|
178
180
|
host += "#{args.delete(:subdomain)}." if args.key?(:subdomain)
|
179
181
|
host += @uri.host
|
180
182
|
host += ":#{@uri.port}" if @uri.port != 80 && @uri.port != 443
|
181
|
-
host + path(name, args)
|
183
|
+
host + path(name, **args)
|
182
184
|
end
|
183
185
|
|
184
186
|
# Add a new, frozen, route to the map.
|
data/lib/rutter/mount.rb
CHANGED
@@ -7,6 +7,15 @@ module Rutter
|
|
7
7
|
#
|
8
8
|
# @private
|
9
9
|
class Mount < Route
|
10
|
+
# @see Rutter::Route#initialize
|
11
|
+
#
|
12
|
+
# @private
|
13
|
+
def initialize(path, endpoint, constraints = nil, host: nil)
|
14
|
+
@host = host
|
15
|
+
|
16
|
+
super(path, endpoint, constraints)
|
17
|
+
end
|
18
|
+
|
10
19
|
# Matches the app pattern against environment.
|
11
20
|
#
|
12
21
|
# @param env [Hash]
|
@@ -15,7 +24,22 @@ module Rutter
|
|
15
24
|
# @return [nil, String]
|
16
25
|
# Returns the matching substring or nil on no match.
|
17
26
|
def match?(env)
|
27
|
+
return if @host && !@host.match?(host(env))
|
28
|
+
|
18
29
|
@pattern.peek(env["PATH_INFO"])
|
19
30
|
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
# @private
|
35
|
+
def host(env)
|
36
|
+
env["rutter.parsed_host"] ||= begin
|
37
|
+
if (forwarded = env["HTTP_X_FORWARDED_HOST"])
|
38
|
+
forwarded.split(/,\s?/).last
|
39
|
+
else
|
40
|
+
env["HTTP_HOST"] || env["SERVER_NAME"] || env["SERVER_ADDR"]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
20
44
|
end
|
21
45
|
end
|
data/lib/rutter/routes.rb
CHANGED
@@ -53,10 +53,11 @@ module Rutter
|
|
53
53
|
protected
|
54
54
|
|
55
55
|
# @private
|
56
|
-
def method_missing(method_name,
|
56
|
+
def method_missing(method_name, **args)
|
57
57
|
named_route, type = method_name.to_s.split(/\_(path|url)\z/)
|
58
58
|
return super unless type
|
59
|
-
|
59
|
+
|
60
|
+
@router.public_send(type, named_route.to_sym, **args)
|
60
61
|
end
|
61
62
|
|
62
63
|
# @private
|
data/lib/rutter/scope.rb
CHANGED
@@ -34,8 +34,8 @@ module Rutter
|
|
34
34
|
end
|
35
35
|
|
36
36
|
# @see Rutter::Builder#mount
|
37
|
-
def mount(app, at:)
|
38
|
-
@router.mount app, at: Naming.join(@path, at)
|
37
|
+
def mount(app, at:, host: nil)
|
38
|
+
@router.mount app, at: Naming.join(@path, at), host: host
|
39
39
|
end
|
40
40
|
|
41
41
|
# @see Rutter::Builder#scope
|
data/lib/rutter/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -2,10 +2,6 @@
|
|
2
2
|
|
3
3
|
require "bundler/setup"
|
4
4
|
|
5
|
-
unless ENV["CI"]
|
6
|
-
require "byebug"
|
7
|
-
end
|
8
|
-
|
9
5
|
if ENV["COVERAGE"] == "true"
|
10
6
|
require "simplecov"
|
11
7
|
|
@@ -13,6 +9,11 @@ if ENV["COVERAGE"] == "true"
|
|
13
9
|
command_name "spec"
|
14
10
|
add_filter "spec"
|
15
11
|
end
|
12
|
+
|
13
|
+
if ENV["CODECOV_TOKEN"]
|
14
|
+
require "codecov"
|
15
|
+
SimpleCov.formatter = SimpleCov::Formatter::Codecov
|
16
|
+
end
|
16
17
|
end
|
17
18
|
|
18
19
|
# Require support (helper) modules
|
data/spec/unit/builder_spec.rb
CHANGED
@@ -18,6 +18,23 @@ module Rutter
|
|
18
18
|
expect(route.match?(env_for("/admin/books")))
|
19
19
|
.to eq("/admin")
|
20
20
|
end
|
21
|
+
|
22
|
+
it "matches host if given" do
|
23
|
+
route = router.mount endpoint, at: "/v1", host: /\Aapi\./
|
24
|
+
|
25
|
+
expect(route.match?(env_for("http://example.com/v1/books")))
|
26
|
+
.to be_nil
|
27
|
+
expect(route.match?(env_for("http://api.example.com/v1/books")))
|
28
|
+
.to eq("/v1")
|
29
|
+
end
|
30
|
+
|
31
|
+
it "HTTP_X_FORWARDED_HOST are supported" do
|
32
|
+
route = router.mount endpoint, at: "/v1", host: /\Aapi\./
|
33
|
+
env = env_for("/v1/books", "HTTP_X_FORWARDED_HOST" => "api.example.com")
|
34
|
+
|
35
|
+
expect(route.match?(env))
|
36
|
+
.to eq("/v1")
|
37
|
+
end
|
21
38
|
end
|
22
39
|
|
23
40
|
describe "#path" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rutter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Sandelius
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mustermann
|
@@ -148,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
148
|
- !ruby/object:Gem::Version
|
149
149
|
version: 2.5.0
|
150
150
|
requirements: []
|
151
|
-
rubygems_version: 3.
|
151
|
+
rubygems_version: 3.1.2
|
152
152
|
signing_key:
|
153
153
|
specification_version: 4
|
154
154
|
summary: HTTP router for Rack.
|