hobby 0.0.11 → 0.0.12

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: efd7204b29860fd75f5957d387a7e3471f29dc4f
4
- data.tar.gz: 39171775abf2b781a075ca41dff0269ec2604b91
3
+ metadata.gz: 2d2d480ccdf4a60839072589bfaa58309a00bf4a
4
+ data.tar.gz: e69b2439193e69c2f53adc780dac6666f71a01e6
5
5
  SHA512:
6
- metadata.gz: 27bd4fe6035a627fd69303caf363ada2a5a295a02358a0d6375a26d7aa8326a0072c49af4e6c93cb4ef4fddc19d93a929ee3091a61409b95a5b508d03ef95669
7
- data.tar.gz: 246e802642e5e7ad4c29c71bf92f826e5553f5ec2c163dec42e8f14bbcd6f6f2dd7d459c8721b6e08fae38c36f0bc4f76c3588a29841b07a5acef362571cac03
6
+ metadata.gz: ff31f1f11344235dec85b8d021008a1b89a18ab65b8e4743add83b8e8e8e3104af567c8bdb01a5e84d6a78c5c9248a95272e3de7f3ac88fc6c60180a3e7266ee
7
+ data.tar.gz: 723ba318c713c9d21c44c3bf8397e48a7204a562c7294545aedd7a26634a402887269878618cc61e91b3a2dcbe3454a0aa590dfde07f1cc51532c0d8123a0f2f
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.11'
7
+ spec.version = '0.0.12'
8
8
  spec.authors = ['Anatoly Chernow']
9
9
  spec.email = ['chertoly@gmail.com']
10
10
  spec.summary = %q{A minimal DSL over rack}
@@ -0,0 +1,34 @@
1
+ module Hobby
2
+ module Helpers
3
+ attr_reader :env, :route
4
+
5
+ def request
6
+ @request ||= self.class.request.new env
7
+ end
8
+
9
+ def response
10
+ @response ||= self.class.response.new
11
+ end
12
+
13
+ def my
14
+ route.params
15
+ end
16
+
17
+ def halt
18
+ throw :halt, response
19
+ end
20
+
21
+ def not_found
22
+ response.status = 404
23
+ end
24
+
25
+ def content_type type
26
+ mime_type = Rack::Mime::MIME_TYPES.fetch ".#{type}"
27
+ response.add_header 'Content-Type', mime_type
28
+ end
29
+
30
+ def status status
31
+ response.status = status
32
+ end
33
+ end
34
+ end
data/lib/hobby.rb CHANGED
@@ -2,6 +2,7 @@ require 'rack'
2
2
  require 'forwardable'
3
3
 
4
4
  require 'hobby/router'
5
+ require 'hobby/helpers'
5
6
 
6
7
  module Hobby
7
8
  App = Hobby # to stay compatible with old code
@@ -31,6 +32,8 @@ module Hobby
31
32
  end
32
33
  end
33
34
 
35
+ include Helpers
36
+
34
37
  def call env
35
38
  dup.handle env
36
39
  end
@@ -39,39 +42,14 @@ module Hobby
39
42
  def handle env
40
43
  catch :halt do
41
44
  @route = self.class.router.route_for (@env = env)
42
-
43
- body = route ? (instance_exec &route) : not_found
44
- response.write body
45
-
45
+ fill_body
46
46
  response
47
47
  end
48
48
  end
49
49
 
50
50
  private
51
- attr_reader :env, :route
52
-
53
- def request
54
- @request ||= self.class.request.new env
55
- end
56
-
57
- def response
58
- @response ||= self.class.response.new
59
- end
60
-
61
- def my
62
- route.params
63
- end
64
-
65
- def halt
66
- throw :halt, response
67
- end
68
-
69
- def not_found
70
- response.status = 404
71
- end
72
-
73
- def content_type type
74
- mime_type = Rack::Mime::MIME_TYPES.fetch ".#{type}"
75
- response.add_header 'Content-Type', mime_type
51
+ def fill_body
52
+ body = route ? (instance_exec &route) : not_found
53
+ response.write body
76
54
  end
77
55
  end
data/readme.adoc CHANGED
@@ -346,7 +346,7 @@ To run the specs:
346
346
  bundle exec rspec
347
347
  ----
348
348
 
349
- To perform mutantion analysis:
349
+ To perform mutation analysis:
350
350
 
351
351
  [source,bash]
352
352
  ----
data/spec/app_spec.rb CHANGED
@@ -163,5 +163,13 @@ describe Hobby::App do
163
163
  assert { last_response.headers['Content-Type'] == 'application/javascript' }
164
164
  end
165
165
  end
166
+
167
+ describe Status do
168
+ it do
169
+ get '/'
170
+ assert { last_response.status == 201 }
171
+ assert { last_response.body == 'Created.' }
172
+ end
173
+ end
166
174
  end
167
175
  end
@@ -0,0 +1,4 @@
1
+ get do
2
+ status 201
3
+ 'Created.'
4
+ end
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.11
4
+ version: 0.0.12
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-07-01 00:00:00.000000000 Z
11
+ date: 2017-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -33,12 +33,11 @@ extra_rdoc_files: []
33
33
  files:
34
34
  - ".gitignore"
35
35
  - ".travis.yml"
36
- - CHANGELOG.md
37
36
  - Gemfile
38
37
  - LICENSE
39
- - Rakefile
40
38
  - hobby.gemspec
41
39
  - lib/hobby.rb
40
+ - lib/hobby/helpers.rb
42
41
  - lib/hobby/router.rb
43
42
  - lib/hobby/router/route.rb
44
43
  - lib/hobby/router/routes.rb
@@ -52,6 +51,7 @@ files:
52
51
  - spec/apps/Map.rb
53
52
  - spec/apps/Nested.rb
54
53
  - spec/apps/OneRouteRouter.rb
54
+ - spec/apps/Status.rb
55
55
  - spec/apps/Use.rb
56
56
  - spec/apps/WithoutPath.rb
57
57
  - spec/helper.rb
@@ -91,6 +91,7 @@ test_files:
91
91
  - spec/apps/Map.rb
92
92
  - spec/apps/Nested.rb
93
93
  - spec/apps/OneRouteRouter.rb
94
+ - spec/apps/Status.rb
94
95
  - spec/apps/Use.rb
95
96
  - spec/apps/WithoutPath.rb
96
97
  - spec/helper.rb
data/CHANGELOG.md DELETED
@@ -1,53 +0,0 @@
1
- # 0.6.0
2
-
3
- * Change the implementation of `Hobbit::Base#halt`. This new implementation is
4
- more rack compliant.
5
- * Test hobbit with [oktobertest](https://github.com/patriciomacadden/oktobertest)
6
- instead of minitest (Because reasons!).
7
-
8
- # 0.5.1 (Unreleased)
9
-
10
- * A class is an object too, so allow to `run` classes.
11
- * Add `Hobbit::Request`, which sets the path info to `/` if its empty (instead
12
- of doing that on the call method).
13
-
14
- # 0.5.0
15
-
16
- * Refactor `Hobbit::Base#halt`. It now sets the status, merges the headers and
17
- writes the body (using `Hobbit::Response#write`) when given a fixnum, a hash or
18
- a string.
19
- * `Hobbit::Response` headers and body are not accessors anymore. This is
20
- because when you set the body directly, the `Content-Length` is not calculated
21
- (it's calculated on `#write`).
22
-
23
- # 0.4.4
24
-
25
- * Refactor `Hobbit::Response`.
26
-
27
- # 0.4.3
28
-
29
- * Calculate the `Content-Length` of a `Hobbit::Response` using `#bytesize`
30
- instead of `#size`.
31
-
32
- # 0.4.2
33
-
34
- * Add `Hobbit::Response#redirect`, that was missing since `Hobbit::Response`
35
- isn't a `Rack::Response` subclass.
36
-
37
- # 0.4.1
38
-
39
- * `Hobbit::Response` now returns the `Content-Length` header as a string.
40
-
41
- # 0.4.0
42
-
43
- * Add halt method.
44
-
45
- # 0.3.1
46
-
47
- * Remove unused `attr_accessor` (`:length`) from `Hobbit::Response`.
48
-
49
- # 0.3.0
50
-
51
- * `Hobbit::Response` is no longer a subclass of `Rack::Response`.
52
- * Forward `#map` and `#use` methods to `Rack::Builder` instead of define these
53
- methods.
data/Rakefile DELETED
@@ -1,4 +0,0 @@
1
- require 'bundler/gem_tasks'
2
- require 'rake/testtask'
3
-
4
- Rake::TestTask.new