syro 2.1.0 → 2.1.1
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 +4 -0
- data/README.md +44 -44
- data/syro.gemspec +2 -2
- data/test/all.rb +87 -87
- metadata +10 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f857bcf1e2b031415f2d9182a062f6dd242f17a0
|
4
|
+
data.tar.gz: 13fb027d2ee19067a1e1da120ee80af13c56d3fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd3d9434647854b6a12c0b543772a0c01141bf52cf653858216132ead9494d9bbf08d7f644d3bc1c767ddda46feff973a9aab30be7e6784aa1f38674e060cc38
|
7
|
+
data.tar.gz: e728e0711a44eaae11c440f2989998f288e50a7668db1ad0ed0a5cda0ad61b6a992ed6a0682c2d20631e0db19830ba8af34179c27eb54ce02070f2944779acab
|
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -33,17 +33,17 @@ Usage
|
|
33
33
|
An example of a modular application would look like this:
|
34
34
|
|
35
35
|
```ruby
|
36
|
-
|
37
|
-
get
|
36
|
+
Admin = Syro.new do
|
37
|
+
get do
|
38
38
|
res.write "Hello from admin!"
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
on
|
44
|
-
run(
|
45
|
-
|
46
|
-
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
App = Syro.new do
|
43
|
+
on "admin" do
|
44
|
+
run(Admin)
|
45
|
+
end
|
46
|
+
end
|
47
47
|
```
|
48
48
|
|
49
49
|
The block is evaluated in a sandbox where the following methods are
|
@@ -138,11 +138,11 @@ class TextualDeck < Syro::Deck
|
|
138
138
|
end
|
139
139
|
end
|
140
140
|
|
141
|
-
App = Syro.new(TextualDeck)
|
142
|
-
get
|
141
|
+
App = Syro.new(TextualDeck) do
|
142
|
+
get do
|
143
143
|
text("hello world")
|
144
|
-
|
145
|
-
|
144
|
+
end
|
145
|
+
end
|
146
146
|
```
|
147
147
|
|
148
148
|
The example is simple enough to showcase the concept, but maybe too
|
@@ -159,47 +159,47 @@ In the following examples, the response string represents
|
|
159
159
|
the request path that was sent.
|
160
160
|
|
161
161
|
```ruby
|
162
|
-
|
163
|
-
get
|
162
|
+
App = Syro.new do
|
163
|
+
get do
|
164
164
|
res.write "GET /"
|
165
|
-
|
165
|
+
end
|
166
166
|
|
167
|
-
post
|
167
|
+
post do
|
168
168
|
res.write "POST /"
|
169
|
-
|
169
|
+
end
|
170
170
|
|
171
|
-
on
|
172
|
-
on
|
171
|
+
on "users" do
|
172
|
+
on :id do
|
173
173
|
|
174
174
|
# Captured values go to the inbox
|
175
175
|
@user = User[inbox[:id]]
|
176
176
|
|
177
|
-
get
|
177
|
+
get do
|
178
178
|
res.write "GET /users/42"
|
179
|
-
|
179
|
+
end
|
180
180
|
|
181
|
-
put
|
181
|
+
put do
|
182
182
|
res.write "PUT /users/42"
|
183
|
-
|
183
|
+
end
|
184
184
|
|
185
|
-
patch
|
185
|
+
patch do
|
186
186
|
res.write "PATCH /users/42"
|
187
|
-
|
187
|
+
end
|
188
188
|
|
189
|
-
delete
|
189
|
+
delete do
|
190
190
|
res.write "DELETE /users/42"
|
191
|
-
|
192
|
-
|
191
|
+
end
|
192
|
+
end
|
193
193
|
|
194
|
-
get
|
194
|
+
get do
|
195
195
|
res.write "GET /users"
|
196
|
-
|
196
|
+
end
|
197
197
|
|
198
|
-
post
|
198
|
+
post do
|
199
199
|
res.write "POST /users"
|
200
|
-
|
201
|
-
|
202
|
-
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
203
|
```
|
204
204
|
|
205
205
|
Matches
|
@@ -234,9 +234,9 @@ a slash and until either another slash or the end of the string.
|
|
234
234
|
The captured value is stored in the `inbox` hash under the key that
|
235
235
|
was provided as the argument to `on`. For example, after a call to
|
236
236
|
`on(:user_id)`, the value for the segment will be stored at
|
237
|
-
`inbox[:user_id]`. When mounting an application called `
|
238
|
-
the command `run(
|
239
|
-
argument: `run(
|
237
|
+
`inbox[:user_id]`. When mounting an application called `Users` with
|
238
|
+
the command `run(Users)`, an inbox can be provided as the second
|
239
|
+
argument: `run(Users, inbox)`. That allows apps to share previous
|
240
240
|
captures.
|
241
241
|
|
242
242
|
Security
|
@@ -259,15 +259,15 @@ Syro doesn't support Rack middleware out of the box. If you need them,
|
|
259
259
|
just use `Rack::Builder`:
|
260
260
|
|
261
261
|
```ruby
|
262
|
-
|
262
|
+
App = Rack::Builder.new do
|
263
263
|
|
264
264
|
use Rack::Session::Cookie, secret: "..."
|
265
265
|
|
266
|
-
run Syro.new
|
267
|
-
get
|
266
|
+
run Syro.new do
|
267
|
+
get do
|
268
268
|
res.write("Hello, world")
|
269
|
-
|
270
|
-
|
269
|
+
end
|
270
|
+
end
|
271
271
|
|
272
272
|
end
|
273
273
|
```
|
data/syro.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "syro"
|
3
|
-
s.version = "2.1.
|
3
|
+
s.version = "2.1.1"
|
4
4
|
s.summary = "Simple router"
|
5
5
|
s.description = "Simple router for web applications"
|
6
6
|
s.authors = ["Michel Martens"]
|
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.files = `git ls-files`.split("\n")
|
12
12
|
|
13
13
|
s.add_dependency "seg"
|
14
|
-
s.add_dependency "rack", "
|
14
|
+
s.add_dependency "rack", ">= 1.6.0", "< 2.0.0"
|
15
15
|
s.add_development_dependency "cutest"
|
16
16
|
s.add_development_dependency "rack-test"
|
17
17
|
end
|
data/test/all.rb
CHANGED
@@ -41,159 +41,159 @@ class CustomRequestAndResponse < Syro::Deck
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
textual = Syro.new(TextualDeck)
|
45
|
-
get
|
44
|
+
textual = Syro.new(TextualDeck) do
|
45
|
+
get do
|
46
46
|
text("GET /textual")
|
47
|
-
|
48
|
-
|
47
|
+
end
|
48
|
+
end
|
49
49
|
|
50
|
-
default_headers = Syro.new(DefaultHeaders)
|
50
|
+
default_headers = Syro.new(DefaultHeaders) do end
|
51
51
|
|
52
|
-
json = Syro.new(CustomRequestAndResponse)
|
53
|
-
root
|
52
|
+
json = Syro.new(CustomRequestAndResponse) do
|
53
|
+
root do
|
54
54
|
params = req.params
|
55
55
|
|
56
56
|
res.write(params)
|
57
|
-
|
58
|
-
|
57
|
+
end
|
58
|
+
end
|
59
59
|
|
60
|
-
admin = Syro.new
|
61
|
-
get
|
60
|
+
admin = Syro.new do
|
61
|
+
get do
|
62
62
|
res.write("GET /admin")
|
63
|
-
|
64
|
-
|
63
|
+
end
|
64
|
+
end
|
65
65
|
|
66
|
-
platforms = Syro.new
|
66
|
+
platforms = Syro.new do
|
67
67
|
@id = inbox.fetch(:id)
|
68
68
|
|
69
|
-
get
|
69
|
+
get do
|
70
70
|
res.write "GET /platforms/#{@id}"
|
71
|
-
|
72
|
-
|
71
|
+
end
|
72
|
+
end
|
73
73
|
|
74
|
-
comments = Syro.new
|
75
|
-
get
|
74
|
+
comments = Syro.new do
|
75
|
+
get do
|
76
76
|
res.write sprintf("GET %s/%s/comments",
|
77
77
|
inbox[:path],
|
78
78
|
inbox[:post_id])
|
79
|
-
|
80
|
-
|
79
|
+
end
|
80
|
+
end
|
81
81
|
|
82
|
-
app = Syro.new
|
83
|
-
get
|
82
|
+
app = Syro.new do
|
83
|
+
get do
|
84
84
|
res.write "GET /"
|
85
|
-
|
85
|
+
end
|
86
86
|
|
87
|
-
post
|
88
|
-
on
|
87
|
+
post do
|
88
|
+
on req.POST["user"] != nil do
|
89
89
|
res.write "POST / (user)"
|
90
|
-
|
90
|
+
end
|
91
91
|
|
92
|
-
on
|
92
|
+
on true do
|
93
93
|
res.write "POST / (none)"
|
94
|
-
|
95
|
-
|
94
|
+
end
|
95
|
+
end
|
96
96
|
|
97
|
-
on
|
98
|
-
on
|
99
|
-
on
|
97
|
+
on "foo" do
|
98
|
+
on "bar" do
|
99
|
+
on "baz" do
|
100
100
|
res.write("error")
|
101
|
-
|
101
|
+
end
|
102
102
|
|
103
|
-
get
|
103
|
+
get do
|
104
104
|
res.write("GET /foo/bar")
|
105
|
-
|
105
|
+
end
|
106
106
|
|
107
|
-
put
|
107
|
+
put do
|
108
108
|
res.write("PUT /foo/bar")
|
109
|
-
|
109
|
+
end
|
110
110
|
|
111
|
-
head
|
111
|
+
head do
|
112
112
|
res.write("HEAD /foo/bar")
|
113
|
-
|
113
|
+
end
|
114
114
|
|
115
|
-
post
|
115
|
+
post do
|
116
116
|
res.write("POST /foo/bar")
|
117
|
-
|
117
|
+
end
|
118
118
|
|
119
|
-
patch
|
119
|
+
patch do
|
120
120
|
res.write("PATCH /foo/bar")
|
121
|
-
|
121
|
+
end
|
122
122
|
|
123
|
-
delete
|
123
|
+
delete do
|
124
124
|
res.write("DELETE /foo/bar")
|
125
|
-
|
125
|
+
end
|
126
126
|
|
127
|
-
options
|
127
|
+
options do
|
128
128
|
res.write("OPTIONS /foo/bar")
|
129
|
-
|
130
|
-
|
131
|
-
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
132
|
|
133
|
-
on
|
134
|
-
get
|
133
|
+
on "bar/baz" do
|
134
|
+
get do
|
135
135
|
res.write("GET /bar/baz")
|
136
|
-
|
137
|
-
|
136
|
+
end
|
137
|
+
end
|
138
138
|
|
139
|
-
on
|
139
|
+
on "admin" do
|
140
140
|
run(admin)
|
141
|
-
|
141
|
+
end
|
142
142
|
|
143
|
-
on
|
143
|
+
on "platforms" do
|
144
144
|
run(platforms, id: 42)
|
145
|
-
|
145
|
+
end
|
146
146
|
|
147
|
-
on
|
147
|
+
on "rack" do
|
148
148
|
run(RackApp.new)
|
149
|
-
|
149
|
+
end
|
150
150
|
|
151
|
-
on
|
152
|
-
on
|
151
|
+
on "users" do
|
152
|
+
on :id do
|
153
153
|
res.write(sprintf("GET /users/%s", inbox[:id]))
|
154
|
-
|
155
|
-
|
154
|
+
end
|
155
|
+
end
|
156
156
|
|
157
|
-
on
|
157
|
+
on "posts" do
|
158
158
|
@path = path.prev
|
159
159
|
|
160
|
-
on
|
161
|
-
on
|
160
|
+
on :post_id do
|
161
|
+
on "comments" do
|
162
162
|
run(comments, inbox.merge(path: @path))
|
163
|
-
|
164
|
-
|
165
|
-
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
166
|
|
167
|
-
on
|
167
|
+
on "one" do
|
168
168
|
@one = "1"
|
169
169
|
|
170
|
-
get
|
170
|
+
get do
|
171
171
|
res.write(@one)
|
172
|
-
|
173
|
-
|
172
|
+
end
|
173
|
+
end
|
174
174
|
|
175
|
-
on
|
176
|
-
get
|
175
|
+
on "two" do
|
176
|
+
get do
|
177
177
|
res.write(@one)
|
178
|
-
|
178
|
+
end
|
179
179
|
|
180
|
-
post
|
180
|
+
post do
|
181
181
|
res.redirect("/one")
|
182
|
-
|
183
|
-
|
182
|
+
end
|
183
|
+
end
|
184
184
|
|
185
|
-
on
|
185
|
+
on "textual" do
|
186
186
|
run(textual)
|
187
|
-
|
187
|
+
end
|
188
188
|
|
189
|
-
on
|
189
|
+
on "headers" do
|
190
190
|
run(default_headers)
|
191
|
-
|
191
|
+
end
|
192
192
|
|
193
|
-
on
|
193
|
+
on "json" do
|
194
194
|
run(json)
|
195
|
-
|
196
|
-
|
195
|
+
end
|
196
|
+
end
|
197
197
|
|
198
198
|
setup do
|
199
199
|
Driver.new(app)
|
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.1.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michel Martens
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: seg
|
@@ -28,16 +28,22 @@ dependencies:
|
|
28
28
|
name: rack
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 1.6.0
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 2.0.0
|
34
37
|
type: :runtime
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
37
40
|
requirements:
|
38
|
-
- - "
|
41
|
+
- - ">="
|
39
42
|
- !ruby/object:Gem::Version
|
40
43
|
version: 1.6.0
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 2.0.0
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: cutest
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|