syro 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +31 -0
- data/lib/syro.rb +5 -4
- data/syro.gemspec +1 -1
- data/test/all.rb +25 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76dac1dc767f0ca11941aba2e7e9ebb44a19dd0f
|
4
|
+
data.tar.gz: 1857b66de5723f4cd08832bf8dedb5b6c089044c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18dba2a7313b529be3dcf7572070a842bf9d389b4878d788d19003b384a7f6548ea6ae45d098c63ef26ce5b7d9da1833d9ba7edf0249047c7d523af7f032c9fa
|
7
|
+
data.tar.gz: 0cd2379ff3ac4edebaca98a1644bf985ebeb187c5aec2f0a5a77e3336ed83c63f4dc43d9f1189d174b3a3199b5f1b9dd8596b7a5dfa2bd1f1fee0585c524cabd
|
data/README.md
CHANGED
@@ -89,6 +89,37 @@ are true.
|
|
89
89
|
`delete`: Receives a block and calls it only if `root?` and `req.delete?`
|
90
90
|
are true.
|
91
91
|
|
92
|
+
Decks
|
93
|
+
-----
|
94
|
+
|
95
|
+
The sandbox where the application is evaluated is an instance of
|
96
|
+
`Syro::Deck`, and it provides the API described earlier. You can
|
97
|
+
define your own `Deck` and pass it to the `Syro` constructor. All
|
98
|
+
the methods defined in there will be accessible from your routes.
|
99
|
+
Here's an example:
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
class TextualDeck < Syro::Deck
|
103
|
+
def text(str)
|
104
|
+
res[Rack::CONTENT_TYPE] = "text/plain"
|
105
|
+
res.write(str)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
App = Syro.new(TextualDeck) {
|
110
|
+
get {
|
111
|
+
text("hello world")
|
112
|
+
}
|
113
|
+
}
|
114
|
+
```
|
115
|
+
|
116
|
+
The example is simple enough to showcase the concept, but maybe too
|
117
|
+
simple to be meaningful. The idea is that you can create your own
|
118
|
+
specialized decks and reuse them in different applications. You can
|
119
|
+
also define modules and later include them in your decks: for
|
120
|
+
example, you can write modules for rendering or serializing data,
|
121
|
+
and then you can combine those modules in your custom decks.
|
122
|
+
|
92
123
|
Examples
|
93
124
|
--------
|
94
125
|
|
data/lib/syro.rb
CHANGED
@@ -83,7 +83,7 @@ class Syro
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
-
class
|
86
|
+
class Deck
|
87
87
|
def initialize(code)
|
88
88
|
@syro_code = code
|
89
89
|
end
|
@@ -195,11 +195,12 @@ class Syro
|
|
195
195
|
end
|
196
196
|
end
|
197
197
|
|
198
|
-
def initialize(&
|
199
|
-
@
|
198
|
+
def initialize(deck = Deck, &code)
|
199
|
+
@deck = deck
|
200
|
+
@code = code
|
200
201
|
end
|
201
202
|
|
202
203
|
def call(env, inbox = {})
|
203
|
-
|
204
|
+
@deck.new(@code).call(env, inbox)
|
204
205
|
end
|
205
206
|
end
|
data/syro.gemspec
CHANGED
data/test/all.rb
CHANGED
@@ -1,6 +1,19 @@
|
|
1
|
+
class TextualDeck < Syro::Deck
|
2
|
+
def text(str)
|
3
|
+
res[Rack::CONTENT_TYPE] = "text/plain"
|
4
|
+
res.write(str)
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
textual = Syro.new(TextualDeck) {
|
9
|
+
get {
|
10
|
+
text("GET /textual")
|
11
|
+
}
|
12
|
+
}
|
13
|
+
|
1
14
|
admin = Syro.new {
|
2
15
|
get {
|
3
|
-
res.write
|
16
|
+
res.write("GET /admin")
|
4
17
|
}
|
5
18
|
}
|
6
19
|
|
@@ -106,6 +119,10 @@ app = Syro.new {
|
|
106
119
|
res.redirect("/one")
|
107
120
|
}
|
108
121
|
}
|
122
|
+
|
123
|
+
on("textual") {
|
124
|
+
run(textual)
|
125
|
+
}
|
109
126
|
}
|
110
127
|
|
111
128
|
setup do
|
@@ -194,3 +211,10 @@ test "redirect" do |f|
|
|
194
211
|
assert_equal "1", f.last_response.body
|
195
212
|
assert_equal 200, f.last_response.status
|
196
213
|
end
|
214
|
+
|
215
|
+
test "custom deck" do |f|
|
216
|
+
f.get("/textual")
|
217
|
+
assert_equal "GET /textual", f.last_response.body
|
218
|
+
assert_equal "text/plain", f.last_response.headers["Content-Type"]
|
219
|
+
assert_equal 200, f.last_response.status
|
220
|
+
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.
|
4
|
+
version: 0.0.4
|
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-04-
|
11
|
+
date: 2015-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: seg
|