syro 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +4 -0
  3. data/README.md +8 -2
  4. data/lib/syro.rb +38 -5
  5. data/syro.gemspec +1 -1
  6. data/test/all.rb +16 -0
  7. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 658a95591ca492f8ef93c5bf53fec487241fe19a
4
- data.tar.gz: 544c047d077ede271e2a07a87a2ab90b7d6c89fd
3
+ metadata.gz: ef99afaf8d8d2f03d42a66cf16b3aa8e76c91a66
4
+ data.tar.gz: 416d45ed7ca4d2c8e995e1b71d7a603f6b655d80
5
5
  SHA512:
6
- metadata.gz: 82e8ee02485eec1edd424f2a02a530a2b14fc1fa5625f1490c3b2b6ce30fc0214e9331139d07ba923af04ff9b86bbbff640bea5ddab38d2446a588b07b4f0629
7
- data.tar.gz: 07a12905d58b323509195f95065bcc6c739115a44345cfd2b5d2f5aff8becc4ba7360d0bd59a3f879aba4dff966fd8e9d375e84a0ce2d05daef447d78d7f161a
6
+ metadata.gz: c755f0d05b8c8c8e7ffa3b1b811e658c7b9182a0632d9b5d15031414295cd97630166c773fc505d87c186d2c2a92e437512b8da6880bd8ae0c903223de7d98c6
7
+ data.tar.gz: 4cf42a210e82910a6997a7f7b54273ff98c2c0442978797d87f98a22aeac21355962f1eaca8024ae9b316a0aa0378e913fab54d41ac3d8ee308edd9052c27993
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ 2.1.0
2
+
3
+ * Add matchers for head and options
4
+
1
5
  2.0.0
2
6
 
3
7
  * No changes since 2.0.0.rc1
data/README.md CHANGED
@@ -49,8 +49,8 @@ app = Syro.new {
49
49
  The block is evaluated in a sandbox where the following methods are
50
50
  available: `env`, `req`, `res`, `path`, `inbox`, `call`, `run`,
51
51
  `halt`, `consume`, `capture`, `root?` `match`, `default`, `on`,
52
- `root`,`get`, `put`, `post`, `patch` and `delete`. Three other
53
- methods are available for customizations: `default_headers`,
52
+ `root`,`get`, `put`, `head`, `post`, `patch`, `delete` and `options`.
53
+ Three other methods are available for customizations: `default_headers`,
54
54
  `request_class` and `response_class`.
55
55
 
56
56
  As a recommendation, user created variables should be instance
@@ -106,6 +106,9 @@ true.
106
106
  `put`: Receives a block and calls it only if `root?` and `req.put?` are
107
107
  true.
108
108
 
109
+ `head`: Receives a block and calls it only if `root?` and `req.head?`
110
+ are true.
111
+
109
112
  `post`: Receives a block and calls it only if `root?` and `req.post?`
110
113
  are true.
111
114
 
@@ -115,6 +118,9 @@ are true.
115
118
  `delete`: Receives a block and calls it only if `root?` and `req.delete?`
116
119
  are true.
117
120
 
121
+ `options`: Receives a block and calls it only if `root?` and
122
+ `req.options?` are true.
123
+
118
124
  Decks
119
125
  -----
120
126
 
data/lib/syro.rb CHANGED
@@ -24,7 +24,7 @@ require "rack"
24
24
  require "seg"
25
25
 
26
26
  class Syro
27
- INBOX = "syro.inbox".freeze
27
+ INBOX = "syro.inbox".freeze # :nodoc:
28
28
 
29
29
  class Response
30
30
  LOCATION = "Location".freeze # :nodoc:
@@ -48,14 +48,14 @@ class Syro
48
48
  # res.body
49
49
  # # => ["there is", "no try"]
50
50
  #
51
- attr :body
51
+ attr_reader :body
52
52
 
53
53
  # Returns a hash with the response headers.
54
54
  #
55
55
  # res.headers
56
56
  # # => { "Content-Type" => "text/html", "Content-Length" => "42" }
57
57
  #
58
- attr :headers
58
+ attr_reader :headers
59
59
 
60
60
  def initialize(headers = {})
61
61
  @status = nil
@@ -179,10 +179,14 @@ class Syro
179
179
  Rack::Utils.set_cookie_header!(@headers, key, value)
180
180
  end
181
181
 
182
- # Deletes cookie.
182
+ # Deletes given cookie.
183
183
  #
184
184
  # res.set_cookie("foo", "bar")
185
185
  # res["Set-Cookie"]
186
+ # # => "foo=bar"
187
+ #
188
+ # res.delete_cookie("foo")
189
+ # res["Set-Cookie"]
186
190
  # # => "foo=; max-age=0; expires=Thu, 01 Jan 1970 00:00:00 -0000"
187
191
  #
188
192
  def delete_cookie(key, value = {})
@@ -200,10 +204,24 @@ class Syro
200
204
  @syro_env
201
205
  end
202
206
 
207
+ # Returns the incoming request object. This object is an
208
+ # instance of Rack::Request.
209
+ #
210
+ # req.post? # => true
211
+ # req.params # => { "username" => "bob", "password" => "secret" }
212
+ # req[:username] # => "bob"
213
+ #
203
214
  def req
204
215
  @syro_req
205
216
  end
206
217
 
218
+ # Returns the current response object. This object is an
219
+ # instance of Syro::Response.
220
+ #
221
+ # res.status = 200
222
+ # res["Content-Type"] = "text/html"
223
+ # res.write("<h1>Welcome back!</h1>")
224
+ #
207
225
  def res
208
226
  @syro_res
209
227
  end
@@ -217,7 +235,7 @@ class Syro
217
235
  end
218
236
 
219
237
  def default_headers
220
- return {}
238
+ {}
221
239
  end
222
240
 
223
241
  def request_class
@@ -254,6 +272,13 @@ class Syro
254
272
  env[Rack::PATH_INFO], env[Rack::SCRIPT_NAME] = path, script
255
273
  end
256
274
 
275
+ # Immediately stops the request and returns `response`
276
+ # as per Rack's specification.
277
+ #
278
+ # halt([200, { "Content-Type" => "text/html" }, ["hello"]])
279
+ # halt([res.status, res.headers, res.body])
280
+ # halt(res.finish)
281
+ #
257
282
  def halt(response)
258
283
  throw(:halt, response)
259
284
  end
@@ -299,6 +324,10 @@ class Syro
299
324
  root { yield } if req.put?
300
325
  end
301
326
 
327
+ def head
328
+ root { yield } if req.head?
329
+ end
330
+
302
331
  def post
303
332
  root { yield } if req.post?
304
333
  end
@@ -310,6 +339,10 @@ class Syro
310
339
  def delete
311
340
  root { yield } if req.delete?
312
341
  end
342
+
343
+ def options
344
+ root { yield } if req.options?
345
+ end
313
346
  end
314
347
 
315
348
  include API
data/syro.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "syro"
3
- s.version = "2.0.0"
3
+ s.version = "2.1.0"
4
4
  s.summary = "Simple router"
5
5
  s.description = "Simple router for web applications"
6
6
  s.authors = ["Michel Martens"]
data/test/all.rb CHANGED
@@ -108,6 +108,10 @@ app = Syro.new {
108
108
  res.write("PUT /foo/bar")
109
109
  }
110
110
 
111
+ head {
112
+ res.write("HEAD /foo/bar")
113
+ }
114
+
111
115
  post {
112
116
  res.write("POST /foo/bar")
113
117
  }
@@ -119,6 +123,10 @@ app = Syro.new {
119
123
  delete {
120
124
  res.write("DELETE /foo/bar")
121
125
  }
126
+
127
+ options {
128
+ res.write("OPTIONS /foo/bar")
129
+ }
122
130
  }
123
131
  }
124
132
 
@@ -200,6 +208,10 @@ test "path + verb" do |f|
200
208
  assert_equal 200, f.last_response.status
201
209
  assert_equal "PUT /foo/bar", f.last_response.body
202
210
 
211
+ f.head("/foo/bar")
212
+ assert_equal 200, f.last_response.status
213
+ assert_equal "HEAD /foo/bar", f.last_response.body
214
+
203
215
  f.post("/foo/bar")
204
216
  assert_equal 200, f.last_response.status
205
217
  assert_equal "POST /foo/bar", f.last_response.body
@@ -211,6 +223,10 @@ test "path + verb" do |f|
211
223
  f.delete("/foo/bar")
212
224
  assert_equal 200, f.last_response.status
213
225
  assert_equal "DELETE /foo/bar", f.last_response.body
226
+
227
+ f.options("/foo/bar")
228
+ assert_equal 200, f.last_response.status
229
+ assert_equal "OPTIONS /foo/bar", f.last_response.body
214
230
  end
215
231
 
216
232
  test "verbs match only on root" do |f|
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: 2.0.0
4
+ version: 2.1.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-12-05 00:00:00.000000000 Z
11
+ date: 2015-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: seg