syro 0.0.8 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +6 -0
  3. data/lib/syro.rb +6 -2
  4. data/syro.gemspec +1 -1
  5. data/test/all.rb +28 -0
  6. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d5bd169764accc1559a997f38c5a350e1b738f10
4
- data.tar.gz: 6fc78b2e65bd001d3a88bbb216c5f9aa214ab889
3
+ metadata.gz: 72ccaea865ce6b7f9dd3c646ff3fffbe74ef3a26
4
+ data.tar.gz: 0254961f899a3579960d806aaeee163517064c09
5
5
  SHA512:
6
- metadata.gz: 2a6cc7183e4c0b977769b34805e7d5dab8665384f986dae55605be896423db304420fb5309fc75b97b8594a131ea7a5536f9b3d21f642122dbab43dbd3ebbb9d
7
- data.tar.gz: 73921b5292db07295b5ee25e90d364093cd6e2d60b4dc9a151bad63ab24e568337a8eddb78c3e87706f3b9bb2bddb64ba98eba98f6d9720274690df0464605c5
6
+ metadata.gz: 1450ad36901c308e28a71ea2a085df6d9803ccfa095dec59bd55cc27f65339d0c876e957faebb9e0579de7f21fda9181c516e979d040a4ec7e7b635e88d8c057
7
+ data.tar.gz: 936d26d701776b2064a5913b686f5660efb389399500048262ebd78357cd377b6960ccb9792b57524cbd10f6b4fe85cf4fedce7b20ad0bb09183180c4bdb3e9c
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ 1.0.0
2
+
3
+ * Yield captures as an alternative API
4
+
5
+ * Add support for default headers in response
6
+
1
7
  0.0.8
2
8
 
3
9
  * Reset PATH_INFO and SCRIPT_NAME after running a subapp
@@ -110,10 +110,14 @@ class Syro
110
110
  @syro_inbox
111
111
  end
112
112
 
113
+ def default_headers
114
+ return {}
115
+ end
116
+
113
117
  def call(env, inbox)
114
118
  @syro_env = env
115
119
  @syro_req = Rack::Request.new(env)
116
- @syro_res = Syro::Response.new
120
+ @syro_res = Syro::Response.new(default_headers)
117
121
  @syro_path = Seg.new(env.fetch(Rack::PATH_INFO))
118
122
  @syro_inbox = inbox
119
123
 
@@ -151,7 +155,7 @@ class Syro
151
155
 
152
156
  def on(arg)
153
157
  if match(arg)
154
- yield
158
+ yield(inbox[arg])
155
159
 
156
160
  halt(res.finish)
157
161
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "syro"
3
- s.version = "0.0.8"
3
+ s.version = "1.0.0"
4
4
  s.summary = "Simple router"
5
5
  s.description = "Simple router for web applications"
6
6
  s.authors = ["Michel Martens"]
@@ -11,12 +11,20 @@ class TextualDeck < Syro::Deck
11
11
  end
12
12
  end
13
13
 
14
+ class DefaultHeaders < Syro::Deck
15
+ def default_headers
16
+ { Rack::CONTENT_TYPE => "text/html" }
17
+ end
18
+ end
19
+
14
20
  textual = Syro.new(TextualDeck) {
15
21
  get {
16
22
  text("GET /textual")
17
23
  }
18
24
  }
19
25
 
26
+ default_headers = Syro.new(DefaultHeaders) { }
27
+
20
28
  admin = Syro.new {
21
29
  get {
22
30
  res.write("GET /admin")
@@ -106,6 +114,12 @@ app = Syro.new {
106
114
  }
107
115
  }
108
116
 
117
+ on("articles") {
118
+ on(:id) { |id|
119
+ res.write(sprintf("GET /articles/%s", id))
120
+ }
121
+ }
122
+
109
123
  on("posts") {
110
124
  @path = path.prev
111
125
 
@@ -137,6 +151,10 @@ app = Syro.new {
137
151
  on("textual") {
138
152
  run(textual)
139
153
  }
154
+
155
+ on("headers") {
156
+ run(default_headers)
157
+ }
140
158
  }
141
159
 
142
160
  setup do
@@ -199,6 +217,10 @@ test "captures" do |f|
199
217
  f.get("/users/42")
200
218
  assert_equal "GET /users/42", f.last_response.body
201
219
  assert_equal 200, f.last_response.status
220
+
221
+ f.get("/articles/23")
222
+ assert_equal "GET /articles/23", f.last_response.body
223
+ assert_equal 200, f.last_response.status
202
224
  end
203
225
 
204
226
  test "post values" do |f|
@@ -242,3 +264,9 @@ test "custom deck" do |f|
242
264
  assert_equal "text/plain", f.last_response.headers["Content-Type"]
243
265
  assert_equal 200, f.last_response.status
244
266
  end
267
+
268
+ test "default headers" do |f|
269
+ f.get("/headers")
270
+
271
+ assert_equal "text/html", f.last_response.headers["Content-Type"]
272
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: syro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michel Martens
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-02 00:00:00.000000000 Z
11
+ date: 2015-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: seg