hobby 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/hobby.gemspec +1 -1
- data/lib/hobby/router/routes.rb +1 -1
- data/readme.adoc +19 -15
- data/spec/router_spec.rb +8 -0
- 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: 39a8b0ef69f89a30fb7a7874d6c3a607d874bf35
|
4
|
+
data.tar.gz: 35a6b8e0c5429b648243eb6b2c17834aa216292a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4cd9d81e9db2ff98e0386bb4ae6803ab616edd637275ee957d95302b09d13ac4a415f56e849720d2d006625a79176875601053afa31cf8d02d551f93889e772
|
7
|
+
data.tar.gz: 7feec3a54880470f1a511a5817168780990c78a6129367dbdb506a03caac7a2ab7d0f853a0107b847430a8cb7b3d9a7d9b8505588e990fdaf78147040957ccf5
|
data/hobby.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = 'hobby'
|
7
|
-
spec.version = '0.0.
|
7
|
+
spec.version = '0.0.10'
|
8
8
|
spec.authors = ['Anatoly Chernow']
|
9
9
|
spec.email = ['chertoly@gmail.com']
|
10
10
|
spec.summary = %q{A minimal DSL over rack}
|
data/lib/hobby/router/routes.rb
CHANGED
@@ -7,7 +7,7 @@ class Hobby::Router
|
|
7
7
|
|
8
8
|
def []= key, route
|
9
9
|
if key.include? ?:
|
10
|
-
string = key.gsub(/(:\w+)/) { "(?<#{$1[1..-1]}>[
|
10
|
+
string = key.gsub(/(:\w+)/) { "(?<#{$1[1..-1]}>[^/?#.]+)" }
|
11
11
|
@patterns[/^#{string}$/] = route
|
12
12
|
else
|
13
13
|
super and super "#{key}/", route
|
data/readme.adoc
CHANGED
@@ -166,6 +166,8 @@ When an incoming request matches a route,
|
|
166
166
|
the action is executed and a response is sent back to the client.
|
167
167
|
The return value of the action will be the `body` of the response.
|
168
168
|
|
169
|
+
=== Default route
|
170
|
+
|
169
171
|
If a path was omitted
|
170
172
|
[source,ruby]
|
171
173
|
----
|
@@ -184,6 +186,22 @@ end
|
|
184
186
|
|
185
187
|
were called.
|
186
188
|
|
189
|
+
=== Route params
|
190
|
+
|
191
|
+
Can be accessed with `route.params` (or a shortcut `my`):
|
192
|
+
|
193
|
+
[source,ruby]
|
194
|
+
----
|
195
|
+
# will match '/index', '/hobby', '/purpose', etc.
|
196
|
+
get '/:name' do
|
197
|
+
route.params[:name]
|
198
|
+
end
|
199
|
+
|
200
|
+
# will match '/index.css', '/index.js', etc.
|
201
|
+
get '/:name.:ext' do
|
202
|
+
"The name is #{my[:name]} and the ext is #{my[:ext]}."
|
203
|
+
end
|
204
|
+
----
|
187
205
|
|
188
206
|
[[default-methods]]
|
189
207
|
== Default methods
|
@@ -194,23 +212,9 @@ The following methods are predefined:
|
|
194
212
|
* `request`: a http://www.rubydoc.info/gems/rack/Rack/Request[`Rack::Request`].
|
195
213
|
* `response`: a http://www.rubydoc.info/gems/rack/Rack/Response[`Rack::Response`].
|
196
214
|
* `route`: a `Hobby::Router::Route`, the currently executing route.
|
197
|
-
* `route.params`, or a shortcut `my`: a `Hash` which stores route params. See <<
|
215
|
+
* `route.params`, or a shortcut `my`: a `Hash` which stores route params. See <<route-params>> for a usage example.
|
198
216
|
* `halt`: returns the `response` immediately. See <<halting>> for a usage example.
|
199
217
|
|
200
|
-
[[routes-params]]
|
201
|
-
=== Routes with params
|
202
|
-
|
203
|
-
[source,ruby]
|
204
|
-
----
|
205
|
-
class App
|
206
|
-
include Hobby
|
207
|
-
# matches both /hi/hobbit and /hi/patricio
|
208
|
-
get '/hi/:name' do
|
209
|
-
"Hello #{my[:name]}"
|
210
|
-
end
|
211
|
-
end
|
212
|
-
----
|
213
|
-
|
214
218
|
[[halting]]
|
215
219
|
=== Halting
|
216
220
|
|
data/spec/router_spec.rb
CHANGED
@@ -11,6 +11,8 @@ describe Hobby::Router do
|
|
11
11
|
/say/:something/to/:someone
|
12
12
|
/route/:id.json
|
13
13
|
/existent/only/for/GET
|
14
|
+
/js/:name.js
|
15
|
+
/dot/:first.:second
|
14
16
|
!
|
15
17
|
|
16
18
|
before { add_routes *routes }
|
@@ -31,6 +33,12 @@ describe Hobby::Router do
|
|
31
33
|
and_set_params(something: 'nothing', someone: 'no_one')
|
32
34
|
end
|
33
35
|
|
36
|
+
it { should find_route('/js/with-js.js').and_set_params(name: 'with-js') }
|
37
|
+
it do
|
38
|
+
should find_route('/dot/aa.wtf').
|
39
|
+
and_set_params(first: 'aa', second: 'wtf')
|
40
|
+
end
|
41
|
+
|
34
42
|
|
35
43
|
it 'memoizes requests with params' do
|
36
44
|
subject.route_for env_for '/hello/ololo'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hobby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anatoly Chernow
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|