syro 1.1.1 → 2.0.0.rc1
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/CHANGELOG +8 -0
- data/README.md +13 -4
- data/lib/syro.rb +19 -11
- data/syro.gemspec +1 -1
- data/test/all.rb +0 -10
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ace9e69fc974748cea5f7ba6b4c19810670e8e7f
|
4
|
+
data.tar.gz: 997281fce4e718304e0007db8dfdfd3feb550f83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e139419c2ba779617205cbdce2f82867d59d9f736aa436a90d32eb5f85676922132da86e57e76b232cf73f05557017903f563ebe02e0cd96eff5d6e1fbb49ba8
|
7
|
+
data.tar.gz: 03580f514c3d8348c66b7a3f1ee8d7eeaf687e3b51c1e45f2057a5bb05c99dd07f38c78b05d1d915f5fbdcb96625697f5f41f998828e8695edf81a4658886eb5
|
data/CHANGELOG
CHANGED
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`, `
|
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
|
264
|
-
when Symbol then
|
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
|
271
|
-
|
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
|
279
|
-
|
286
|
+
def on(arg)
|
287
|
+
default { yield } if match(arg)
|
280
288
|
end
|
281
289
|
|
282
290
|
def root
|
283
|
-
|
291
|
+
default { yield } if root?
|
284
292
|
end
|
285
293
|
|
286
294
|
def get
|
data/syro.gemspec
CHANGED
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:
|
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-
|
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:
|
103
|
+
version: 1.3.1
|
104
104
|
requirements: []
|
105
105
|
rubyforge_project:
|
106
106
|
rubygems_version: 2.4.5.1
|