syro 1.1.1 → 2.0.0.rc1

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 +8 -0
  3. data/README.md +13 -4
  4. data/lib/syro.rb +19 -11
  5. data/syro.gemspec +1 -1
  6. data/test/all.rb +0 -10
  7. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 68e7e12639d6b627c7968f0b3490f5a910d43e5a
4
- data.tar.gz: 8c81dc6869e463804f9162ee1e5bb2fb27596734
3
+ metadata.gz: ace9e69fc974748cea5f7ba6b4c19810670e8e7f
4
+ data.tar.gz: 997281fce4e718304e0007db8dfdfd3feb550f83
5
5
  SHA512:
6
- metadata.gz: 0f971c4823ead5c999a91c29f473513dd03dcaafb6b31f090830c16f392fc86d4727cdca61400c0e82f81e4478877d841554a7cb567f209a6d139c9bfbcfe5c4
7
- data.tar.gz: 444459d6f617d91775b880d2db7b1b0abfffc3b6da4646a3d5b8b129c8c2f6b5b447ba9c8180af35f2b506f49c4e83748fec47fe0c63a22d269caa539b436068
6
+ metadata.gz: e139419c2ba779617205cbdce2f82867d59d9f736aa436a90d32eb5f85676922132da86e57e76b232cf73f05557017903f563ebe02e0cd96eff5d6e1fbb49ba8
7
+ data.tar.gz: 03580f514c3d8348c66b7a3f1ee8d7eeaf687e3b51c1e45f2057a5bb05c99dd07f38c78b05d1d915f5fbdcb96625697f5f41f998828e8695edf81a4658886eb5
data/CHANGELOG CHANGED
@@ -1,3 +1,11 @@
1
+ 2.0.0.rc1
2
+
3
+ * Add consume and capture primitives
4
+
5
+ * Add default matcher
6
+
7
+ * Revert yield of captured value (was added in 1.0.0)
8
+
1
9
  1.1.1
2
10
 
3
11
  * Small internal refactoring
data/README.md CHANGED
@@ -48,8 +48,10 @@ app = Syro.new {
48
48
 
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
- `halt`, `match`, `on`, `root?`, `root`,`get`, `put`, `post`, `patch`
52
- and `delete`.
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`,
54
+ `request_class` and `response_class`.
53
55
 
54
56
  As a recommendation, user created variables should be instance
55
57
  variables. That way they won't mix with the API methods defined in
@@ -81,14 +83,21 @@ argument.
81
83
  `halt`: Terminates the request. It receives an array with the
82
84
  response as per Rack's specification.
83
85
 
86
+ `consume`: Match and consume a path segment.
87
+
88
+ `capture`: Match and capture a path segment. The value is stored in
89
+ the inbox.
90
+
91
+ `root?`: Returns true if the path yet to be consumed is empty.
92
+
84
93
  `match`: Receives a String, a Symbol or a boolean, and returns true
85
94
  if it matches the request.
86
95
 
96
+ `default`: Receives a block that will be executed inconditionally.
97
+
87
98
  `on`: Receives a value to be matched, and a block that will be
88
99
  executed only if the request is matched.
89
100
 
90
- `root?`: Returns true if the path yet to be consumed is empty.
91
-
92
101
  `root`: Receives a block and calls it only if `root?` is true.
93
102
 
94
103
  `get`: Receives a block and calls it only if `root?` and `req.get?` are
data/lib/syro.rb CHANGED
@@ -258,29 +258,37 @@ class Syro
258
258
  throw(:halt, response)
259
259
  end
260
260
 
261
+ def consume(arg)
262
+ @syro_path.consume(arg)
263
+ end
264
+
265
+ def capture(arg)
266
+ @syro_path.capture(arg, inbox)
267
+ end
268
+
269
+ def root?
270
+ @syro_path.root?
271
+ end
272
+
261
273
  def match(arg)
262
274
  case arg
263
- when String then @syro_path.consume(arg)
264
- when Symbol then @syro_path.capture(arg, inbox)
275
+ when String then consume(arg)
276
+ when Symbol then capture(arg)
265
277
  when true then true
266
278
  else false
267
279
  end
268
280
  end
269
281
 
270
- def on(arg)
271
- if match(arg)
272
- yield(inbox[arg])
273
-
274
- halt(res.finish)
275
- end
282
+ def default
283
+ yield; halt(res.finish)
276
284
  end
277
285
 
278
- def root?
279
- @syro_path.root?
286
+ def on(arg)
287
+ default { yield } if match(arg)
280
288
  end
281
289
 
282
290
  def root
283
- on(root?) { yield }
291
+ default { yield } if root?
284
292
  end
285
293
 
286
294
  def get
data/syro.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "syro"
3
- s.version = "1.1.1"
3
+ s.version = "2.0.0.rc1"
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
@@ -146,12 +146,6 @@ app = Syro.new {
146
146
  }
147
147
  }
148
148
 
149
- on("articles") {
150
- on(:id) { |id|
151
- res.write(sprintf("GET /articles/%s", id))
152
- }
153
- }
154
-
155
149
  on("posts") {
156
150
  @path = path.prev
157
151
 
@@ -253,10 +247,6 @@ test "captures" do |f|
253
247
  f.get("/users/42")
254
248
  assert_equal "GET /users/42", f.last_response.body
255
249
  assert_equal 200, f.last_response.status
256
-
257
- f.get("/articles/23")
258
- assert_equal "GET /articles/23", f.last_response.body
259
- assert_equal 200, f.last_response.status
260
250
  end
261
251
 
262
252
  test "post values" 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: 1.1.1
4
+ version: 2.0.0.rc1
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-03 00:00:00.000000000 Z
11
+ date: 2015-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: seg
@@ -98,9 +98,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
98
98
  version: '0'
99
99
  required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - ">"
102
102
  - !ruby/object:Gem::Version
103
- version: '0'
103
+ version: 1.3.1
104
104
  requirements: []
105
105
  rubyforge_project:
106
106
  rubygems_version: 2.4.5.1