hobbit 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +232 -17
- data/hobbit.gemspec +5 -3
- data/lib/hobbit.rb +1 -0
- data/lib/hobbit/base.rb +24 -21
- data/lib/hobbit/response.rb +10 -0
- data/lib/hobbit/version.rb +1 -1
- data/spec/base_spec.rb +43 -11
- data/spec/minitest_helper.rb +8 -4
- data/spec/render_spec.rb +11 -1
- data/spec/response_spec.rb +9 -0
- data/spec/session_spec.rb +13 -1
- data/spec/version_spec.rb +1 -1
- metadata +46 -28
- data/examples/example_1/Gemfile +0 -3
- data/examples/example_1/app.rb +0 -9
- data/examples/example_1/config.ru +0 -6
- data/examples/example_2/Gemfile +0 -3
- data/examples/example_2/app.rb +0 -7
- data/examples/example_2/config.ru +0 -6
- data/examples/example_2/views/index.erb +0 -7
- data/spec/fixtures/test_base_app.rb +0 -8
- data/spec/fixtures/test_render_app.rb +0 -10
- data/spec/fixtures/test_session_app.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9539a9f971f1c9ce832fc5d01b91426268ae7ad5
|
4
|
+
data.tar.gz: ba9c03f191da3ca5582ffd605a860e58b4d1b6e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9d0975a41d756f846b0f188039af5783de409f56e5637c8599eaa12cd2a218d351a5e100cabe7a87b03bcd2e7b7b9e7996fded1cf542680fcaeb7028cd70805
|
7
|
+
data.tar.gz: 4d492a410464fe67e13e015e8ef2307a58a19701be4661d99a42f445c6dea7157517bd64ade2bafd9f76931d1cf707e608b1f28d2f25d175708c1aadc94b88e1
|
data/README.md
CHANGED
@@ -30,8 +30,13 @@ $ gem install hobbit
|
|
30
30
|
## Features
|
31
31
|
|
32
32
|
* DSL inspired by [Sinatra](http://www.sinatrarb.com/).
|
33
|
-
* Extensible with standard ruby classes and modules, with no extra logic (
|
34
|
-
the included modules).
|
33
|
+
* Extensible with standard ruby classes and modules, with no extra logic (See
|
34
|
+
the included modules and [hobbit-contrib](https://github.com/patriciomacadden/hobbit-contrib)).
|
35
|
+
* No configuration needed.
|
36
|
+
* Encourages the understanding and use of [Rack](http://rack.github.io/) and
|
37
|
+
its extensions.
|
38
|
+
* Request and response classes could be injected (Defaults to `Rack::Request`
|
39
|
+
and `Hobbit::Response`, respectively).
|
35
40
|
|
36
41
|
## Usage
|
37
42
|
|
@@ -52,6 +57,10 @@ end
|
|
52
57
|
run App.new
|
53
58
|
```
|
54
59
|
|
60
|
+
**Note**: In the examples, the classes are written in the `config.ru` file.
|
61
|
+
However, this is not recommended. Please, **always** follow the coding
|
62
|
+
standards!
|
63
|
+
|
55
64
|
### Routes
|
56
65
|
|
57
66
|
You can define routes as in [Sinatra](http://www.sinatrarb.com/):
|
@@ -72,7 +81,7 @@ Every route is composed of a verb, a path and a block. When an incoming request
|
|
72
81
|
matches a route, the block is executed and a response is sent back to the
|
73
82
|
client. The return value of the block will be the `body` of the response. The
|
74
83
|
`headers` and `status code` of the response will be calculated by
|
75
|
-
`
|
84
|
+
`Hobbit::Response`, but you could modify it anyway you want it.
|
76
85
|
|
77
86
|
Additionally, when a route gets called you have this methods available:
|
78
87
|
|
@@ -80,6 +89,59 @@ Additionally, when a route gets called you have this methods available:
|
|
80
89
|
* `request`: a `Rack::Request` instance.
|
81
90
|
* `response`: a `Rack::Response` instance.
|
82
91
|
|
92
|
+
#### Available methods
|
93
|
+
|
94
|
+
* `delete`
|
95
|
+
* `get`
|
96
|
+
* `head`
|
97
|
+
* `options`
|
98
|
+
* `patch`
|
99
|
+
* `post`
|
100
|
+
* `put`
|
101
|
+
|
102
|
+
**Note**: Since most browsers don't support methods other than **GET** and
|
103
|
+
**POST** you must use the `Rack::MethodOverride` middleware. (See
|
104
|
+
[Rack::MethodOverride](https://github.com/rack/rack/blob/master/lib/rack/methodoverride.rb)).
|
105
|
+
Here is an example on how to use it in a RESTful way:
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
require 'hobbit'
|
109
|
+
|
110
|
+
class App < Hobbit::Base
|
111
|
+
use Rack::MethodOverride
|
112
|
+
|
113
|
+
get '/users' do
|
114
|
+
# list the users
|
115
|
+
end
|
116
|
+
|
117
|
+
get '/users/new' do
|
118
|
+
# render a form for creating an user
|
119
|
+
end
|
120
|
+
|
121
|
+
post '/users' do
|
122
|
+
# create an user
|
123
|
+
end
|
124
|
+
|
125
|
+
get '/users/:id/edit' do
|
126
|
+
# render a form for editing an user
|
127
|
+
end
|
128
|
+
|
129
|
+
put '/users/:id' do
|
130
|
+
# update an user
|
131
|
+
end
|
132
|
+
|
133
|
+
get '/users/:id' do
|
134
|
+
# show an user
|
135
|
+
end
|
136
|
+
|
137
|
+
delete '/users/:id' do
|
138
|
+
# delete an user
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
run App.new
|
143
|
+
```
|
144
|
+
|
83
145
|
### Rendering
|
84
146
|
|
85
147
|
`Hobbit` comes with a module that uses [Tilt](https://github.com/rtomayko/tilt)
|
@@ -115,6 +177,9 @@ and in `views/index.erb`:
|
|
115
177
|
</html>
|
116
178
|
```
|
117
179
|
|
180
|
+
**Note**: If you want to use other template engine than `erb`, you should
|
181
|
+
require the gem, ie. add the gem to your `Gemfile`.
|
182
|
+
|
118
183
|
#### Layout
|
119
184
|
|
120
185
|
For now, the `Hobbit::Render` module is pretty simple (just `render`). If you
|
@@ -228,6 +293,81 @@ end
|
|
228
293
|
run App.new
|
229
294
|
```
|
230
295
|
|
296
|
+
### Built on rack
|
297
|
+
|
298
|
+
Each hobbit application is a Rack stack (See this [blog post](http://m.onkey.org/ruby-on-rack-2-the-builder)).
|
299
|
+
|
300
|
+
#### Mapping applications
|
301
|
+
|
302
|
+
You can mount any Rack application to the stack by using the `map` class
|
303
|
+
method:
|
304
|
+
|
305
|
+
```ruby
|
306
|
+
require 'hobbit'
|
307
|
+
|
308
|
+
class InnerApp < Hobbit::Base
|
309
|
+
# gets called when path_info = '/inner'
|
310
|
+
get do
|
311
|
+
'Hello InnerApp!'
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
class App < Hobbit::Base
|
316
|
+
map('/inner') { run InnerApp.new }
|
317
|
+
|
318
|
+
get '/' do
|
319
|
+
'Hello App!'
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
run App.new
|
324
|
+
```
|
325
|
+
|
326
|
+
#### Using middleware
|
327
|
+
|
328
|
+
You can add any Rack middleware to the stack by using the `use` class method:
|
329
|
+
|
330
|
+
```ruby
|
331
|
+
require 'hobbit'
|
332
|
+
|
333
|
+
class App < Hobbit::Base
|
334
|
+
include Hobbit::Session
|
335
|
+
use Rack::Session::Cookie, secret: SecureRandom.hex(64)
|
336
|
+
use Rack::ShowExceptions
|
337
|
+
|
338
|
+
get '/' do
|
339
|
+
session[:name] = 'hobbit'
|
340
|
+
end
|
341
|
+
|
342
|
+
# more routes...
|
343
|
+
end
|
344
|
+
|
345
|
+
run App.new
|
346
|
+
```
|
347
|
+
|
348
|
+
### Security
|
349
|
+
|
350
|
+
By default, `hobbit` (nor Rack) comes without any protection against web
|
351
|
+
attacks. The use of [Rack::Protection](https://github.com/rkh/rack-protection)
|
352
|
+
is highly recommended:
|
353
|
+
|
354
|
+
```ruby
|
355
|
+
require 'hobbit'
|
356
|
+
require 'rack/protection'
|
357
|
+
require 'securerandom'
|
358
|
+
|
359
|
+
class App < Hobbit::Base
|
360
|
+
use Rack::Session::Cookie, secret: SecureRandom.hex(64)
|
361
|
+
use Rack::Protection
|
362
|
+
|
363
|
+
get '/' do
|
364
|
+
'Hello World!'
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
368
|
+
run App.new
|
369
|
+
```
|
370
|
+
|
231
371
|
### Sessions
|
232
372
|
|
233
373
|
You can add user sessions using any [Rack session middleware](https://github.com/rack/rack/tree/master/lib/rack/session)
|
@@ -242,7 +382,7 @@ class App < Hobbit::Base
|
|
242
382
|
include Hobbit::Session
|
243
383
|
use Rack::Session::Cookie, secret: SecureRandom.hex(64)
|
244
384
|
|
245
|
-
|
385
|
+
post '/' do
|
246
386
|
session[:name] = 'hobbit'
|
247
387
|
end
|
248
388
|
|
@@ -254,37 +394,112 @@ end
|
|
254
394
|
run App.new
|
255
395
|
```
|
256
396
|
|
257
|
-
###
|
397
|
+
### Static files
|
258
398
|
|
259
|
-
|
260
|
-
|
399
|
+
`Hobbit` does not serve static files like images, javascripts and stylesheets.
|
400
|
+
However, you can serve static files using the `Rack::Static` middleware. Here
|
401
|
+
is an example (See [Rack::Static](https://github.com/rack/rack/blob/master/lib/rack/static.rb)
|
402
|
+
for further details):
|
403
|
+
|
404
|
+
In `config.ru`
|
261
405
|
|
262
406
|
```ruby
|
263
407
|
require 'hobbit'
|
264
408
|
|
265
409
|
class App < Hobbit::Base
|
266
|
-
include Hobbit::
|
267
|
-
use Rack::
|
268
|
-
use Rack::ShowExceptions
|
410
|
+
include Hobbit::Render
|
411
|
+
use Rack::Static, root: 'public', urls: ['/javascripts', '/stylesheets']
|
269
412
|
|
270
413
|
get '/' do
|
271
|
-
|
414
|
+
render 'views/index.erb'
|
272
415
|
end
|
416
|
+
end
|
273
417
|
|
274
|
-
|
418
|
+
run App.new
|
419
|
+
```
|
420
|
+
|
421
|
+
In `views/index.erb`:
|
422
|
+
|
423
|
+
```ruby
|
424
|
+
<!DOCTYPE html>
|
425
|
+
<html>
|
426
|
+
<head>
|
427
|
+
<title>Hello World!</title>
|
428
|
+
<link href="/stylesheets/application.css" rel="stylesheet"/>
|
429
|
+
<script src="/javascripts/application.js" type="text/javascript"></script>
|
430
|
+
</head>
|
431
|
+
<body>
|
432
|
+
<h1>Hello World!</h1>
|
433
|
+
</body>
|
434
|
+
</html>
|
435
|
+
```
|
436
|
+
|
437
|
+
In `public/javascripts/application.js`:
|
438
|
+
|
439
|
+
```js
|
440
|
+
alert(1);
|
441
|
+
```
|
442
|
+
|
443
|
+
In `public/stylesheets/application.css`:
|
444
|
+
|
445
|
+
```css
|
446
|
+
h1 { color: blue; }
|
447
|
+
```
|
448
|
+
|
449
|
+
### Testing Hobbit applications
|
450
|
+
|
451
|
+
[rack-test](https://github.com/brynary/rack-test) is highly recommended. See
|
452
|
+
an example:
|
453
|
+
|
454
|
+
In `app.rb`:
|
455
|
+
|
456
|
+
```ruby
|
457
|
+
require 'hobbit'
|
458
|
+
|
459
|
+
class App < Hobbit::Base
|
460
|
+
get '/' do
|
461
|
+
'Hello World!'
|
462
|
+
end
|
275
463
|
end
|
276
464
|
|
277
|
-
run App
|
465
|
+
run App.new
|
278
466
|
```
|
279
467
|
|
280
|
-
|
468
|
+
In `app_spec.rb`:
|
469
|
+
|
470
|
+
```ruby
|
471
|
+
require 'minitest/autorun'
|
472
|
+
# imagine that app.rb and app_spec.rb are stored in the same directory
|
473
|
+
require 'app'
|
474
|
+
|
475
|
+
describe App do
|
476
|
+
include Rack::Test::Methods
|
477
|
+
|
478
|
+
def app
|
479
|
+
App.new
|
480
|
+
end
|
481
|
+
|
482
|
+
describe 'GET /' do
|
483
|
+
it 'must be ok' do
|
484
|
+
get '/'
|
485
|
+
last_response.must_be :ok?
|
486
|
+
last_response.body.must_match /Hello World!/
|
487
|
+
end
|
488
|
+
end
|
489
|
+
end
|
490
|
+
```
|
491
|
+
|
492
|
+
Please see the [rack-test](https://github.com/brynary/rack-test) documentation.
|
493
|
+
|
494
|
+
## Extending Hobbit
|
281
495
|
|
282
496
|
You can extend hobbit by creating modules or classes. See `Hobbit::Render` or
|
283
497
|
`Hobbit::Session` for examples.
|
284
498
|
|
285
|
-
|
499
|
+
### Hobbit::Contrib
|
286
500
|
|
287
|
-
See
|
501
|
+
See [hobbit-contrib](https://github.com/patriciomacadden/hobbit-contrib) for
|
502
|
+
more hobbit extensions!
|
288
503
|
|
289
504
|
## Contributing
|
290
505
|
|
@@ -296,4 +511,4 @@ See the `examples` directory.
|
|
296
511
|
|
297
512
|
## License
|
298
513
|
|
299
|
-
See the [LICENSE](https://github.com/patriciomacadden/hobbit/blob/master/LICENSE).
|
514
|
+
See the [LICENSE](https://github.com/patriciomacadden/hobbit/blob/master/LICENSE).
|
data/hobbit.gemspec
CHANGED
@@ -18,11 +18,13 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_dependency 'rack'
|
22
|
-
spec.add_dependency 'tilt'
|
23
|
-
|
24
21
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
25
22
|
spec.add_development_dependency 'minitest'
|
23
|
+
spec.add_development_dependency 'rack'
|
26
24
|
spec.add_development_dependency 'rack-test'
|
27
25
|
spec.add_development_dependency 'rake'
|
26
|
+
spec.add_development_dependency 'tilt'
|
27
|
+
|
28
|
+
spec.add_runtime_dependency 'rack'
|
29
|
+
spec.add_runtime_dependency 'tilt'
|
28
30
|
end
|
data/lib/hobbit.rb
CHANGED
data/lib/hobbit/base.rb
CHANGED
@@ -2,25 +2,33 @@ module Hobbit
|
|
2
2
|
class Base
|
3
3
|
class << self
|
4
4
|
%w(DELETE GET HEAD OPTIONS PATCH POST PUT).each do |verb|
|
5
|
-
define_method(verb.downcase) { |path, &block| routes[verb] << compile_route!(path, &block) }
|
5
|
+
define_method(verb.downcase) { |path = '', &block| routes[verb] << compile_route!(path, &block) }
|
6
6
|
end
|
7
7
|
|
8
|
-
def
|
9
|
-
|
8
|
+
def map(path, &block)
|
9
|
+
stack.map(path, &block)
|
10
10
|
end
|
11
11
|
|
12
12
|
alias :new! :new
|
13
13
|
def new(*args, &block)
|
14
|
-
|
15
|
-
|
14
|
+
stack.run new!(*args, &block)
|
15
|
+
stack
|
16
16
|
end
|
17
17
|
|
18
18
|
def routes
|
19
19
|
@routes ||= Hash.new { |hash, key| hash[key] = [] }
|
20
20
|
end
|
21
21
|
|
22
|
+
def settings
|
23
|
+
@settings ||= { request_class: Rack::Request, response_class: Hobbit::Response }
|
24
|
+
end
|
25
|
+
|
26
|
+
def stack
|
27
|
+
@stack ||= Rack::Builder.new
|
28
|
+
end
|
29
|
+
|
22
30
|
def use(middleware, *args, &block)
|
23
|
-
|
31
|
+
stack.use(middleware, *args, &block)
|
24
32
|
end
|
25
33
|
|
26
34
|
private
|
@@ -46,8 +54,8 @@ module Hobbit
|
|
46
54
|
|
47
55
|
def _call(env)
|
48
56
|
@env = env
|
49
|
-
@request =
|
50
|
-
@response =
|
57
|
+
@request = self.class.settings[:request_class].new(@env)
|
58
|
+
@response = self.class.settings[:response_class].new
|
51
59
|
route_eval
|
52
60
|
@response.finish
|
53
61
|
end
|
@@ -55,20 +63,15 @@ module Hobbit
|
|
55
63
|
private
|
56
64
|
|
57
65
|
def route_eval
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
param = route[:extra_params][index]
|
64
|
-
@request.params[param] = value
|
65
|
-
end
|
66
|
-
end
|
67
|
-
@response.write instance_eval(&route[:block])
|
68
|
-
throw :halt
|
69
|
-
end
|
66
|
+
route = self.class.routes[request.request_method].detect { |r| r[:compiled_path] =~ request.path_info }
|
67
|
+
if route
|
68
|
+
route[:compiled_path].match(request.path_info).captures.each_with_index do |value, index|
|
69
|
+
param = route[:extra_params][index]
|
70
|
+
request.params[param] = value
|
70
71
|
end
|
71
|
-
|
72
|
+
response.write instance_eval(&route[:block])
|
73
|
+
else
|
74
|
+
response.status = 404
|
72
75
|
end
|
73
76
|
end
|
74
77
|
end
|
data/lib/hobbit/version.rb
CHANGED
data/spec/base_spec.rb
CHANGED
@@ -1,22 +1,31 @@
|
|
1
1
|
require 'minitest_helper'
|
2
2
|
|
3
3
|
describe Hobbit::Base do
|
4
|
+
include Hobbit::Mock
|
4
5
|
include Rack::Test::Methods
|
5
6
|
|
6
7
|
def app
|
7
|
-
|
8
|
+
mock_app do
|
9
|
+
%w(DELETE GET HEAD OPTIONS PATCH POST PUT).each do |verb|
|
10
|
+
class_eval "#{verb.downcase} { '#{verb}' }"
|
11
|
+
class_eval "#{verb.downcase}('/') { '#{verb}' }"
|
12
|
+
class_eval "#{verb.downcase}('/route.json') { '#{verb} /route.json' }"
|
13
|
+
class_eval "#{verb.downcase}('/route/:id.json') { request.params[:id] }"
|
14
|
+
class_eval "#{verb.downcase}('/:name') { request.params[:name] }"
|
15
|
+
end
|
16
|
+
end
|
8
17
|
end
|
9
18
|
|
10
19
|
%w(DELETE GET HEAD OPTIONS PATCH POST PUT).each do |verb|
|
11
20
|
str = <<EOS
|
12
21
|
describe "::#{verb.downcase}" do
|
13
22
|
it 'must add a route to @routes' do
|
14
|
-
|
15
|
-
|
23
|
+
route = app.to_app.class.routes['#{verb}'].first
|
24
|
+
route[:path].must_equal ''
|
16
25
|
end
|
17
26
|
|
18
27
|
it 'must extract the extra_params' do
|
19
|
-
route =
|
28
|
+
route = app.to_app.class.routes['#{verb}'].last
|
20
29
|
route[:extra_params].must_equal [:name]
|
21
30
|
end
|
22
31
|
end
|
@@ -24,26 +33,50 @@ EOS
|
|
24
33
|
class_eval str
|
25
34
|
end
|
26
35
|
|
27
|
-
describe '::
|
36
|
+
describe '::settings' do
|
37
|
+
let(:settings) { app.to_app.class.settings }
|
38
|
+
|
39
|
+
it 'must return a hash with (at least) a request_class and response_class keys' do
|
40
|
+
settings.must_be_kind_of Hash
|
41
|
+
settings.must_include :request_class
|
42
|
+
settings.must_include :response_class
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'must be initialized with request_class as Rack::Request' do
|
46
|
+
settings[:request_class].must_equal Rack::Request
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'must be initialized with request_class as Hobbit::Response' do
|
50
|
+
settings[:response_class].must_equal Hobbit::Response
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '::stack' do
|
28
55
|
it 'must return an instance of Rack::Builder' do
|
29
|
-
|
56
|
+
app.to_app.class.stack.must_be_kind_of Rack::Builder
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe '::map' do
|
61
|
+
it 'must mount a application to the rack stack' do
|
62
|
+
skip '::map'
|
30
63
|
end
|
31
64
|
end
|
32
65
|
|
33
66
|
describe '::new' do
|
34
67
|
it 'should return an instance of Rack::Builder' do
|
35
|
-
|
68
|
+
app.must_be_kind_of Rack::Builder
|
36
69
|
end
|
37
70
|
end
|
38
71
|
|
39
72
|
describe '::routes' do
|
40
73
|
it 'must return a Hash' do
|
41
|
-
|
74
|
+
app.to_app.class.routes.must_be_kind_of Hash
|
42
75
|
end
|
43
76
|
end
|
44
77
|
|
45
78
|
describe '::use' do
|
46
|
-
it 'must add a middleware to the
|
79
|
+
it 'must add a middleware to the rack stack' do
|
47
80
|
skip '::use'
|
48
81
|
end
|
49
82
|
end
|
@@ -94,7 +127,6 @@ EOS
|
|
94
127
|
end
|
95
128
|
|
96
129
|
it 'must respond to call' do
|
97
|
-
app
|
98
|
-
app.must_respond_to :call
|
130
|
+
app.to_app.must_respond_to :call
|
99
131
|
end
|
100
132
|
end
|
data/spec/minitest_helper.rb
CHANGED
@@ -9,7 +9,11 @@ require 'rack/test'
|
|
9
9
|
|
10
10
|
require 'hobbit'
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
module Hobbit
|
13
|
+
module Mock
|
14
|
+
def mock_app(&block)
|
15
|
+
app = Class.new Hobbit::Base, &block
|
16
|
+
app.new
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/spec/render_spec.rb
CHANGED
@@ -1,10 +1,20 @@
|
|
1
1
|
require 'minitest_helper'
|
2
2
|
|
3
3
|
describe Hobbit::Render do
|
4
|
+
include Hobbit::Mock
|
4
5
|
include Rack::Test::Methods
|
5
6
|
|
6
7
|
def app
|
7
|
-
|
8
|
+
mock_app do
|
9
|
+
include Hobbit::Render
|
10
|
+
|
11
|
+
def name
|
12
|
+
'Hobbit'
|
13
|
+
end
|
14
|
+
|
15
|
+
get('/') { render File.expand_path('../fixtures/views/index.erb', __FILE__) }
|
16
|
+
get('/using-context') { render File.expand_path('../fixtures/views/hello.erb', __FILE__) }
|
17
|
+
end
|
8
18
|
end
|
9
19
|
|
10
20
|
describe '#render' do
|
data/spec/session_spec.rb
CHANGED
@@ -1,10 +1,22 @@
|
|
1
1
|
require 'minitest_helper'
|
2
2
|
|
3
3
|
describe Hobbit::Session do
|
4
|
+
include Hobbit::Mock
|
4
5
|
include Rack::Test::Methods
|
5
6
|
|
6
7
|
def app
|
7
|
-
|
8
|
+
mock_app do
|
9
|
+
include Hobbit::Session
|
10
|
+
use Rack::Session::Cookie, secret: SecureRandom.hex(64)
|
11
|
+
|
12
|
+
get '/' do
|
13
|
+
session[:name] = 'hobbit'
|
14
|
+
end
|
15
|
+
|
16
|
+
get '/name' do
|
17
|
+
session[:name]
|
18
|
+
end
|
19
|
+
end
|
8
20
|
end
|
9
21
|
|
10
22
|
describe '#session' do
|
data/spec/version_spec.rb
CHANGED
metadata
CHANGED
@@ -1,23 +1,37 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hobbit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patricio Mac Adden
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-04-
|
11
|
+
date: 2013-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
31
|
- - '>='
|
18
32
|
- !ruby/object:Gem::Version
|
19
33
|
version: '0'
|
20
|
-
type: :
|
34
|
+
type: :development
|
21
35
|
prerelease: false
|
22
36
|
version_requirements: !ruby/object:Gem::Requirement
|
23
37
|
requirements:
|
@@ -25,13 +39,13 @@ dependencies:
|
|
25
39
|
- !ruby/object:Gem::Version
|
26
40
|
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
42
|
+
name: rack
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - '>='
|
32
46
|
- !ruby/object:Gem::Version
|
33
47
|
version: '0'
|
34
|
-
type: :
|
48
|
+
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
@@ -39,21 +53,21 @@ dependencies:
|
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
56
|
+
name: rack-test
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
|
-
- -
|
59
|
+
- - '>='
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
61
|
+
version: '0'
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
|
-
- -
|
66
|
+
- - '>='
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: rake
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - '>='
|
@@ -67,7 +81,7 @@ dependencies:
|
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
84
|
+
name: tilt
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
87
|
- - '>='
|
@@ -81,13 +95,27 @@ dependencies:
|
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
98
|
+
name: rack
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
101
|
- - '>='
|
88
102
|
- !ruby/object:Gem::Version
|
89
103
|
version: '0'
|
90
|
-
type: :
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: tilt
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
91
119
|
prerelease: false
|
92
120
|
version_requirements: !ruby/object:Gem::Requirement
|
93
121
|
requirements:
|
@@ -107,27 +135,19 @@ files:
|
|
107
135
|
- LICENSE
|
108
136
|
- README.md
|
109
137
|
- Rakefile
|
110
|
-
- examples/example_1/Gemfile
|
111
|
-
- examples/example_1/app.rb
|
112
|
-
- examples/example_1/config.ru
|
113
|
-
- examples/example_2/Gemfile
|
114
|
-
- examples/example_2/app.rb
|
115
|
-
- examples/example_2/config.ru
|
116
|
-
- examples/example_2/views/index.erb
|
117
138
|
- hobbit.gemspec
|
118
139
|
- lib/hobbit.rb
|
119
140
|
- lib/hobbit/base.rb
|
120
141
|
- lib/hobbit/render.rb
|
142
|
+
- lib/hobbit/response.rb
|
121
143
|
- lib/hobbit/session.rb
|
122
144
|
- lib/hobbit/version.rb
|
123
145
|
- spec/base_spec.rb
|
124
|
-
- spec/fixtures/test_base_app.rb
|
125
|
-
- spec/fixtures/test_render_app.rb
|
126
|
-
- spec/fixtures/test_session_app.rb
|
127
146
|
- spec/fixtures/views/hello.erb
|
128
147
|
- spec/fixtures/views/index.erb
|
129
148
|
- spec/minitest_helper.rb
|
130
149
|
- spec/render_spec.rb
|
150
|
+
- spec/response_spec.rb
|
131
151
|
- spec/session_spec.rb
|
132
152
|
- spec/version_spec.rb
|
133
153
|
homepage: ''
|
@@ -156,12 +176,10 @@ specification_version: 4
|
|
156
176
|
summary: A minimalistic microframework built on top of rack
|
157
177
|
test_files:
|
158
178
|
- spec/base_spec.rb
|
159
|
-
- spec/fixtures/test_base_app.rb
|
160
|
-
- spec/fixtures/test_render_app.rb
|
161
|
-
- spec/fixtures/test_session_app.rb
|
162
179
|
- spec/fixtures/views/hello.erb
|
163
180
|
- spec/fixtures/views/index.erb
|
164
181
|
- spec/minitest_helper.rb
|
165
182
|
- spec/render_spec.rb
|
183
|
+
- spec/response_spec.rb
|
166
184
|
- spec/session_spec.rb
|
167
185
|
- spec/version_spec.rb
|
data/examples/example_1/Gemfile
DELETED
data/examples/example_1/app.rb
DELETED
data/examples/example_2/Gemfile
DELETED
data/examples/example_2/app.rb
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
class TestBaseApp < Hobbit::Base
|
2
|
-
%w(DELETE GET HEAD OPTIONS PATCH POST PUT).each do |verb|
|
3
|
-
class_eval "#{verb.downcase}('/') { '#{verb}' }"
|
4
|
-
class_eval "#{verb.downcase}('/route.json') { '#{verb} /route.json' }"
|
5
|
-
class_eval "#{verb.downcase}('/route/:id.json') { request.params[:id] }"
|
6
|
-
class_eval "#{verb.downcase}('/:name') { request.params[:name] }"
|
7
|
-
end
|
8
|
-
end
|