regal 0.2.1 → 1.0.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 +5 -5
- data/lib/regal/app.rb +3 -4
- data/lib/regal/response.rb +1 -1
- data/lib/regal/version.rb +1 -1
- data/spec/regal/app_spec.rb +116 -14
- metadata +6 -11
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: ef206f9aa897e6b16abeb2b835eed4a6ad20709f58fe4be98f7d6f2a43cc8511
|
|
4
|
+
data.tar.gz: 372d5656715377d810b81df4031465303b066762d8bd5d36947168e00ae61ab4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4cff885e626bd9e3041084832c7732f49e89eb8a54f688080ea74193eed68ef311f7a532e7e24b1b6a1594f59633caecd9898d94961b36fa842d07344b87a5c7
|
|
7
|
+
data.tar.gz: d44c0b141c83ae570703be9b23b1237c0e5bbcd8d8e3c2893dfe7c44d950e600c68c80ced1fa9f5f27c5bb294058bd3cbbe5aa8e88d227fa5982c0cde22d1a40
|
data/lib/regal/app.rb
CHANGED
|
@@ -58,6 +58,7 @@ module Regal
|
|
|
58
58
|
MountGraft.new(app, route)
|
|
59
59
|
end
|
|
60
60
|
routes.merge!(mounted_routes)
|
|
61
|
+
routes.default = mounted_routes.default
|
|
61
62
|
end
|
|
62
63
|
@routes.each do |path, cls|
|
|
63
64
|
routes[path] = cls.new(attributes)
|
|
@@ -354,9 +355,9 @@ module Regal
|
|
|
354
355
|
end
|
|
355
356
|
response
|
|
356
357
|
elsif matching_route
|
|
357
|
-
|
|
358
|
+
[405, {}, []]
|
|
358
359
|
else
|
|
359
|
-
|
|
360
|
+
[404, {}, []]
|
|
360
361
|
end
|
|
361
362
|
end
|
|
362
363
|
|
|
@@ -373,8 +374,6 @@ module Regal
|
|
|
373
374
|
|
|
374
375
|
private
|
|
375
376
|
|
|
376
|
-
METHOD_NOT_ALLOWED_RESPONSE = [405, {}.freeze, [].freeze].freeze
|
|
377
|
-
NOT_FOUND_RESPONSE = [404, {}.freeze, [].freeze].freeze
|
|
378
377
|
SLASH = '/'.freeze
|
|
379
378
|
PATH_INFO_KEY = 'PATH_INFO'.freeze
|
|
380
379
|
REQUEST_METHOD_KEY = 'REQUEST_METHOD'.freeze
|
data/lib/regal/response.rb
CHANGED
data/lib/regal/version.rb
CHANGED
data/spec/regal/app_spec.rb
CHANGED
|
@@ -126,7 +126,7 @@ module Regal
|
|
|
126
126
|
|
|
127
127
|
it 'can set response headers' do
|
|
128
128
|
get '/redirect'
|
|
129
|
-
expect(last_response.headers).to include('
|
|
129
|
+
expect(last_response.headers).to include('location' => 'somewhere/else')
|
|
130
130
|
end
|
|
131
131
|
end
|
|
132
132
|
|
|
@@ -262,11 +262,11 @@ module Regal
|
|
|
262
262
|
|
|
263
263
|
it 'does not call further handlers or before blocks when the response is marked as finished' do
|
|
264
264
|
expect(last_response.body).to eq('Go somewhere else')
|
|
265
|
-
expect(last_response.headers).to_not have_key('
|
|
265
|
+
expect(last_response.headers).to_not have_key('x-handlercalled')
|
|
266
266
|
end
|
|
267
267
|
|
|
268
268
|
it 'calls after blocks' do
|
|
269
|
-
expect(last_response.headers).to include('
|
|
269
|
+
expect(last_response.headers).to include('wasaftercalled' => 'yes')
|
|
270
270
|
end
|
|
271
271
|
end
|
|
272
272
|
|
|
@@ -592,6 +592,27 @@ module Regal
|
|
|
592
592
|
end
|
|
593
593
|
end
|
|
594
594
|
|
|
595
|
+
context 'an app that has a top-level capturing route' do
|
|
596
|
+
let :app do
|
|
597
|
+
App.new do
|
|
598
|
+
route :foo do
|
|
599
|
+
get do
|
|
600
|
+
'whatever'
|
|
601
|
+
end
|
|
602
|
+
end
|
|
603
|
+
end
|
|
604
|
+
end
|
|
605
|
+
|
|
606
|
+
it 'matches anything for the capture route' do
|
|
607
|
+
get '/something'
|
|
608
|
+
expect(last_response.status).to eq(200)
|
|
609
|
+
expect(last_response.body).to eq('whatever')
|
|
610
|
+
get '/something-else'
|
|
611
|
+
expect(last_response.status).to eq(200)
|
|
612
|
+
expect(last_response.body).to eq('whatever')
|
|
613
|
+
end
|
|
614
|
+
end
|
|
615
|
+
|
|
595
616
|
context 'an app that mounts another app' do
|
|
596
617
|
GoodbyeApp = App.create do
|
|
597
618
|
route 'goodbye' do
|
|
@@ -701,6 +722,87 @@ module Regal
|
|
|
701
722
|
end
|
|
702
723
|
end
|
|
703
724
|
|
|
725
|
+
context 'an app that has an mounted capturing route' do
|
|
726
|
+
let :app do
|
|
727
|
+
InnerApp = App.create do
|
|
728
|
+
route 'static' do
|
|
729
|
+
get do
|
|
730
|
+
'static'
|
|
731
|
+
end
|
|
732
|
+
end
|
|
733
|
+
|
|
734
|
+
route :bar do
|
|
735
|
+
get do
|
|
736
|
+
'inside'
|
|
737
|
+
end
|
|
738
|
+
end
|
|
739
|
+
end
|
|
740
|
+
|
|
741
|
+
App.new do
|
|
742
|
+
route 'foo' do
|
|
743
|
+
mount InnerApp
|
|
744
|
+
end
|
|
745
|
+
|
|
746
|
+
route :outside do
|
|
747
|
+
get do
|
|
748
|
+
'outside'
|
|
749
|
+
end
|
|
750
|
+
end
|
|
751
|
+
end
|
|
752
|
+
end
|
|
753
|
+
|
|
754
|
+
it 'prioritizes the static route' do
|
|
755
|
+
get '/foo/static'
|
|
756
|
+
expect(last_response.status).to eq(200)
|
|
757
|
+
expect(last_response.body).to eq('static')
|
|
758
|
+
end
|
|
759
|
+
|
|
760
|
+
it 'matches anything for the mounted capture route' do
|
|
761
|
+
get '/foo/this'
|
|
762
|
+
expect(last_response.status).to eq(200)
|
|
763
|
+
expect(last_response.body).to eq('inside')
|
|
764
|
+
end
|
|
765
|
+
|
|
766
|
+
it 'still matches anything for the parent capture route' do
|
|
767
|
+
get '/this'
|
|
768
|
+
expect(last_response.status).to eq(200)
|
|
769
|
+
expect(last_response.body).to eq('outside')
|
|
770
|
+
end
|
|
771
|
+
end
|
|
772
|
+
|
|
773
|
+
context 'an app that has two mounted capturing routes' do
|
|
774
|
+
let :app do
|
|
775
|
+
InnerApp1 = App.create do
|
|
776
|
+
route :bar do
|
|
777
|
+
get do
|
|
778
|
+
'inside 1'
|
|
779
|
+
end
|
|
780
|
+
end
|
|
781
|
+
end
|
|
782
|
+
|
|
783
|
+
InnerApp2 = App.create do
|
|
784
|
+
route :bar do
|
|
785
|
+
get do
|
|
786
|
+
'inside 2'
|
|
787
|
+
end
|
|
788
|
+
end
|
|
789
|
+
end
|
|
790
|
+
|
|
791
|
+
App.new do
|
|
792
|
+
route 'foo' do
|
|
793
|
+
mount InnerApp1
|
|
794
|
+
mount InnerApp2
|
|
795
|
+
end
|
|
796
|
+
end
|
|
797
|
+
end
|
|
798
|
+
|
|
799
|
+
it 'last capture route replaces earlier mounted capture route' do
|
|
800
|
+
get '/foo/this'
|
|
801
|
+
expect(last_response.status).to eq(200)
|
|
802
|
+
expect(last_response.body).to eq('inside 2')
|
|
803
|
+
end
|
|
804
|
+
end
|
|
805
|
+
|
|
704
806
|
context 'an app that groups routes together in scopes' do
|
|
705
807
|
let :app do
|
|
706
808
|
App.new do
|
|
@@ -780,28 +882,28 @@ module Regal
|
|
|
780
882
|
it 'calls the route\'s parent scope\'s before blocks only' do
|
|
781
883
|
get '/scoped/1'
|
|
782
884
|
expect(last_response.status).to eq(200)
|
|
783
|
-
expect(last_response.headers).to include('
|
|
885
|
+
expect(last_response.headers).to include('beforescope' => '1')
|
|
784
886
|
get '/scoped/2'
|
|
785
887
|
expect(last_response.status).to eq(200)
|
|
786
|
-
expect(last_response.headers).to include('
|
|
888
|
+
expect(last_response.headers).to include('beforescope' => '2', 'beforesubscope' => '2')
|
|
787
889
|
end
|
|
788
890
|
|
|
789
891
|
it 'calls the route\'s parent scope\'s after blocks only' do
|
|
790
892
|
get '/scoped/1'
|
|
791
893
|
expect(last_response.status).to eq(200)
|
|
792
|
-
expect(last_response.headers).to include('
|
|
894
|
+
expect(last_response.headers).to include('afterscope' => '1')
|
|
793
895
|
get '/scoped/2'
|
|
794
896
|
expect(last_response.status).to eq(200)
|
|
795
|
-
expect(last_response.headers).to include('
|
|
897
|
+
expect(last_response.headers).to include('afterscope' => '2')
|
|
796
898
|
end
|
|
797
899
|
|
|
798
900
|
it 'calls the common before and after blocks' do
|
|
799
901
|
get '/scoped/1'
|
|
800
902
|
expect(last_response.status).to eq(200)
|
|
801
|
-
expect(last_response.headers).to include('
|
|
903
|
+
expect(last_response.headers).to include('commonbefore' => 'yes', 'commonafter' => 'yes')
|
|
802
904
|
get '/scoped/2'
|
|
803
905
|
expect(last_response.status).to eq(200)
|
|
804
|
-
expect(last_response.headers).to include('
|
|
906
|
+
expect(last_response.headers).to include('commonbefore' => 'yes', 'commonafter' => 'yes')
|
|
805
907
|
end
|
|
806
908
|
end
|
|
807
909
|
|
|
@@ -1310,7 +1412,7 @@ module Regal
|
|
|
1310
1412
|
|
|
1311
1413
|
it 'calls after blocks when errors are handled' do
|
|
1312
1414
|
get '/handled'
|
|
1313
|
-
expect(last_response.headers['
|
|
1415
|
+
expect(last_response.headers['wasaftercalled']).to eq('yes')
|
|
1314
1416
|
end
|
|
1315
1417
|
|
|
1316
1418
|
it 'lets them bubble all the way up when there are no matching error handlers' do
|
|
@@ -1326,12 +1428,12 @@ module Regal
|
|
|
1326
1428
|
|
|
1327
1429
|
it 'delegates them to matching error handlers at the same level, not below' do
|
|
1328
1430
|
get '/handled/at-the-right-level/level-3/level-4'
|
|
1329
|
-
expect(last_response.headers).to include('
|
|
1431
|
+
expect(last_response.headers).to include('handledatlevel' => '3')
|
|
1330
1432
|
end
|
|
1331
1433
|
|
|
1332
1434
|
it 'calls after blocks when errors are handled' do
|
|
1333
1435
|
get '/handled/from-before'
|
|
1334
|
-
expect(last_response.headers['
|
|
1436
|
+
expect(last_response.headers['wasaftercalled']).to eq('yes')
|
|
1335
1437
|
end
|
|
1336
1438
|
|
|
1337
1439
|
end
|
|
@@ -1344,8 +1446,8 @@ module Regal
|
|
|
1344
1446
|
|
|
1345
1447
|
it 'calls the rest of the after blocks when errors are handled' do
|
|
1346
1448
|
get '/handled/from-after'
|
|
1347
|
-
expect(last_response.headers['
|
|
1348
|
-
expect(last_response.headers['
|
|
1449
|
+
expect(last_response.headers['nextafterwascalled']).to eq('yes')
|
|
1450
|
+
expect(last_response.headers['wasaftercalled']).to eq('yes')
|
|
1349
1451
|
end
|
|
1350
1452
|
end
|
|
1351
1453
|
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: regal
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Theo Hultberg
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: rack
|
|
@@ -16,14 +15,14 @@ dependencies:
|
|
|
16
15
|
requirements:
|
|
17
16
|
- - "~>"
|
|
18
17
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
18
|
+
version: '3.0'
|
|
20
19
|
type: :runtime
|
|
21
20
|
prerelease: false
|
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
22
|
requirements:
|
|
24
23
|
- - "~>"
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '
|
|
25
|
+
version: '3.0'
|
|
27
26
|
description: ''
|
|
28
27
|
email:
|
|
29
28
|
- theo@iconara.net
|
|
@@ -46,7 +45,6 @@ homepage: http://github.com/iconara/regal
|
|
|
46
45
|
licenses:
|
|
47
46
|
- BSD-3-Clause
|
|
48
47
|
metadata: {}
|
|
49
|
-
post_install_message:
|
|
50
48
|
rdoc_options: []
|
|
51
49
|
require_paths:
|
|
52
50
|
- lib
|
|
@@ -54,16 +52,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
54
52
|
requirements:
|
|
55
53
|
- - ">="
|
|
56
54
|
- !ruby/object:Gem::Version
|
|
57
|
-
version:
|
|
55
|
+
version: 2.4.0
|
|
58
56
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
57
|
requirements:
|
|
60
58
|
- - ">="
|
|
61
59
|
- !ruby/object:Gem::Version
|
|
62
60
|
version: '0'
|
|
63
61
|
requirements: []
|
|
64
|
-
|
|
65
|
-
rubygems_version: 2.4.5
|
|
66
|
-
signing_key:
|
|
62
|
+
rubygems_version: 3.6.9
|
|
67
63
|
specification_version: 4
|
|
68
64
|
summary: ''
|
|
69
65
|
test_files:
|
|
@@ -71,4 +67,3 @@ test_files:
|
|
|
71
67
|
- spec/regal/request_spec.rb
|
|
72
68
|
- spec/regal/response_spec.rb
|
|
73
69
|
- spec/spec_helper.rb
|
|
74
|
-
has_rdoc:
|