jellyfish 0.8.0 → 0.9.0

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: 30753a754648b5b6d9a72d9165c763b3e4db9383
4
- data.tar.gz: dc78ee33ce6341c19ff571bb78ab2485ef5f2fbd
3
+ metadata.gz: 1bbff880b25384a19ae38417f6318fa77b8bbc4b
4
+ data.tar.gz: 391a9abc638194dfb1ac7f662b57659ccba104bd
5
5
  SHA512:
6
- metadata.gz: aa1d7ff64073a23ffb0b8d4d218e5e2f3ec898c102ad2ee7786c2af062792be705b2941ca98f7fc3e59b095ec88945b3788b065eb22b48e00eae041be930843e
7
- data.tar.gz: 1f33f9aa6f449b034e81c1fb33e30e91c91a580e1310230e487649606add2afeaddf13fa10ea9a9daac1dc878797a390d6211e7486315ff9ee19b34012acb225
6
+ metadata.gz: e1ce357a54f83f8e3f28d28e49b493ef15e7702cc28198b8d6a75d29e7983d062b8685dcdee5bb3f61d8c05b2fa3af833c656c9a24f4f8d11b1e4aa9f2f9254f
7
+ data.tar.gz: cbeb51d8505790c6cd404a1f3e464afbcfe5e1e8077af069a1896eb4f77a33578aadcf30d2d73708c4d9fd724a394667038e0623304f49800d78e55db454a4ed
data/CHANGES.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # CHANGES
2
2
 
3
+ ## Jellyfish 0.9.0
4
+
5
+ ### Enhancements for Jellyfish core
6
+
7
+ * We no longer use exceptions to control the flow. Use
8
+ `halt(InternalError.new)` instead. However, raising exceptions
9
+ would still work. Just prefer to use `halt` if you would like
10
+ some performance boost.
11
+
12
+ ### Incompatible changes
13
+
14
+ * If you're raising `NotFound` instead of using `forward` in your app,
15
+ it would no longer forward the request but show a 404 page. Always
16
+ use `forward` if you intend to forward the request.
17
+
3
18
  ## Jellyfish 0.8.0
4
19
 
5
20
  ### Incompatible changes
data/README.md CHANGED
@@ -13,7 +13,7 @@ by Lin Jen-Shin ([godfat](http://godfat.org))
13
13
  ## DESCRIPTION:
14
14
 
15
15
  Pico web framework for building API-centric web applications.
16
- For Rack applications or Rack middlewares. Around 200 lines of code.
16
+ For Rack applications or Rack middlewares. Around 250 lines of code.
17
17
 
18
18
  ## DESIGN:
19
19
 
@@ -45,7 +45,7 @@ Because Sinatra is too complex and inconsistent for me.
45
45
 
46
46
  ## REQUIREMENTS:
47
47
 
48
- * Tested with MRI (official CRuby) 1.9.3, Rubinius and JRuby.
48
+ * Tested with MRI (official CRuby) 1.9.3, 2.0.0, Rubinius and JRuby.
49
49
 
50
50
  ## INSTALLATION:
51
51
 
data/jellyfish.gemspec CHANGED
@@ -2,12 +2,12 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "jellyfish"
5
- s.version = "0.8.0"
5
+ s.version = "0.9.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Lin Jen-Shin (godfat)"]
9
- s.date = "2013-06-15"
10
- s.description = "Pico web framework for building API-centric web applications.\nFor Rack applications or Rack middlewares. Around 200 lines of code."
9
+ s.date = "2013-07-11"
10
+ s.description = "Pico web framework for building API-centric web applications.\nFor Rack applications or Rack middlewares. Around 250 lines of code."
11
11
  s.email = ["godfat (XD) godfat.org"]
12
12
  s.files = [
13
13
  ".gitignore",
@@ -45,7 +45,7 @@ Gem::Specification.new do |s|
45
45
  s.homepage = "https://github.com/godfat/jellyfish"
46
46
  s.licenses = ["Apache License 2.0"]
47
47
  s.require_paths = ["lib"]
48
- s.rubygems_version = "2.0.3"
48
+ s.rubygems_version = "2.0.4"
49
49
  s.summary = "Pico web framework for building API-centric web applications."
50
50
  s.test_files = [
51
51
  "test/sinatra/test_base.rb",
data/lib/jellyfish.rb CHANGED
@@ -11,6 +11,7 @@ module Jellyfish
11
11
  autoload :ChunkedBody, 'jellyfish/chunked_body'
12
12
 
13
13
  GetValue = Object.new
14
+ Identity = lambda{|_|_}
14
15
 
15
16
  class Response < RuntimeError
16
17
  def headers
@@ -57,8 +58,8 @@ module Jellyfish
57
58
 
58
59
  def request ; @request ||= Rack::Request.new(env); end
59
60
  def halt *args; throw(:halt, *args) ; end
60
- def forward ; raise(Jellyfish::NotFound.new) ; end
61
- def found url; raise(Jellyfish:: Found.new(url)); end
61
+ def forward ; halt(Jellyfish::NotFound.new) ; end
62
+ def found url; halt(Jellyfish:: Found.new(url)); end
62
63
  alias_method :redirect, :found
63
64
 
64
65
  def path_info ; env['PATH_INFO'] || '/' ; end
@@ -96,7 +97,7 @@ module Jellyfish
96
97
 
97
98
  private
98
99
  def actions
99
- routes[request_method.downcase] || raise(Jellyfish::NotFound.new)
100
+ routes[request_method.downcase] || halt(Jellyfish::NotFound.new)
100
101
  end
101
102
 
102
103
  def dispatch
@@ -108,7 +109,7 @@ module Jellyfish
108
109
  match = route.match(path_info)
109
110
  break match, block if match
110
111
  end
111
- } || raise(Jellyfish::NotFound.new)
112
+ } || halt(Jellyfish::NotFound.new)
112
113
  end
113
114
 
114
115
  def with_each value
@@ -174,16 +175,13 @@ module Jellyfish
174
175
 
175
176
  def call env
176
177
  ctrl = self.class.controller.new(self.class.routes, self)
177
- ctrl.call(env)
178
- rescue NotFound => e # forward
179
- if app
180
- begin
181
- app.call(env)
182
- rescue Exception => e
183
- handle(ctrl, e, env['rack.errors'])
184
- end
178
+ case res = catch(:halt){ ctrl.call(env) }
179
+ when NotFound
180
+ app && forward(ctrl, env) || handle(ctrl, res)
181
+ when Response
182
+ handle(ctrl, res, env['rack.errors'])
185
183
  else
186
- handle(ctrl, e)
184
+ res || ctrl.block_call(nil, Identity)
187
185
  end
188
186
  rescue Exception => e
189
187
  handle(ctrl, e, env['rack.errors'])
@@ -200,6 +198,12 @@ module Jellyfish
200
198
  end
201
199
 
202
200
  private
201
+ def forward ctrl, env
202
+ app.call(env)
203
+ rescue Exception => e
204
+ handle(ctrl, e, env['rack.errors'])
205
+ end
206
+
203
207
  def handle ctrl, e, stderr=nil
204
208
  if handler = best_handler(e)
205
209
  ctrl.block_call(e, handler)
@@ -5,13 +5,9 @@ require 'jellyfish'
5
5
 
6
6
  module Jellyfish
7
7
  module MultiActions
8
- Identity = lambda{|_|_}
9
-
10
8
  def call env
11
9
  @env = env
12
- catch(:halt){
13
- dispatch.inject(nil){ |_, route_block| block_call(*route_block) }
14
- } || block_call(nil, Identity) # respond the default if halted
10
+ dispatch.inject(nil){ |_, route_block| block_call(*route_block) }
15
11
  end
16
12
 
17
13
  def dispatch
@@ -26,7 +22,7 @@ module Jellyfish
26
22
  }.compact
27
23
 
28
24
  if acts.empty?
29
- raise(Jellyfish::NotFound.new)
25
+ halt(Jellyfish::NotFound.new)
30
26
  else
31
27
  acts
32
28
  end
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Jellyfish
3
- VERSION = '0.8.0'
3
+ VERSION = '0.9.0'
4
4
  end
@@ -37,37 +37,31 @@ describe 'Sinatra base_test.rb' do
37
37
  end
38
38
 
39
39
  describe 'Jellyfish as a Rack middleware' do
40
- behaves_like :jellyfish
41
-
42
- def app
43
- @app ||= Class.new{
44
- include Jellyfish
45
- get '/' do
46
- 'Hello from middleware'
47
- end
48
-
49
- get '/low-level-forward' do
50
- status, headers, body = jellyfish.app.call(env)
51
- self.status status
52
- self.headers headers
53
- body
54
- end
55
-
56
- get '/explicit-forward' do
57
- headers_merge 'X-Middleware' => 'true'
58
- status, headers, _ = jellyfish.app.call(env)
59
- self.status status
60
- self.headers headers
61
- 'Hello after explicit forward'
62
- end
63
- }.new(inner_app)
64
- end
40
+ inner_app ||= lambda{ |env|
41
+ [210, {'X-Downstream' => 'true'}, ['Hello from downstream']]
42
+ }
65
43
 
66
- def inner_app
67
- @inner_app ||= lambda{ |env|
68
- [210, {'X-Downstream' => 'true'}, ['Hello from downstream']]
69
- }
70
- end
44
+ app = Class.new{
45
+ include Jellyfish
46
+ get '/' do
47
+ 'Hello from middleware'
48
+ end
49
+
50
+ get '/low-level-forward' do
51
+ status, headers, body = jellyfish.app.call(env)
52
+ self.status status
53
+ self.headers headers
54
+ body
55
+ end
56
+
57
+ get '/explicit-forward' do
58
+ headers_merge 'X-Middleware' => 'true'
59
+ status, headers, _ = jellyfish.app.call(env)
60
+ self.status status
61
+ self.headers headers
62
+ 'Hello after explicit forward'
63
+ end
64
+ }.new(inner_app)
71
65
 
72
66
  should 'create a middleware that responds to #call with .new' do
73
67
  app.respond_to?(:call).should.eq true
@@ -78,20 +72,20 @@ describe 'Sinatra base_test.rb' do
78
72
  end
79
73
 
80
74
  should 'intercept requests' do
81
- status, _, body = get('/')
75
+ status, _, body = get('/', app)
82
76
  status.should.eq 200
83
77
  body .should.eq ['Hello from middleware']
84
78
  end
85
79
 
86
80
  should 'forward requests downstream when no matching route found' do
87
- status, headers, body = get('/missing')
81
+ status, headers, body = get('/missing', app)
88
82
  status .should.eq 210
89
83
  headers['X-Downstream'].should.eq 'true'
90
84
  body .should.eq ['Hello from downstream']
91
85
  end
92
86
 
93
87
  should 'call the downstream app directly and return result' do
94
- status, headers, body = get('/low-level-forward')
88
+ status, headers, body = get('/low-level-forward', app)
95
89
  status .should.eq 210
96
90
  headers['X-Downstream'].should.eq 'true'
97
91
  body .should.eq ['Hello from downstream']
@@ -111,7 +111,7 @@ describe 'Sinatra mapped_error_test.rb' do
111
111
  get('/'){ raise e }
112
112
  }.new
113
113
 
114
- status, _, body = get('/', app)
114
+ status, _, _ = get('/', app)
115
115
  status.should.eq 404
116
116
  end
117
117
 
@@ -98,7 +98,7 @@ describe 'Sinatra routing_test.rb' do
98
98
  get('/'){ 'worked' }
99
99
  }.new
100
100
 
101
- status, headers, body = get('', app)
101
+ status, _, body = get('', app)
102
102
  status.should.eq 200
103
103
  body .should.eq ['worked']
104
104
  end
@@ -300,7 +300,6 @@ describe 'Sinatra routing_test.rb' do
300
300
  get '/next' do
301
301
  body 'Hello World'
302
302
  next
303
- 'Boo-hoo World'
304
303
  end
305
304
 
306
305
  get '/halt' do
@@ -340,7 +339,6 @@ describe 'Sinatra routing_test.rb' do
340
339
  get %r{^/(?<foo>\w+)} do
341
340
  params['foo'].should.eq 'bar'
342
341
  next
343
- 'Hello Foo'
344
342
  end
345
343
 
346
344
  get do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jellyfish
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lin Jen-Shin (godfat)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-15 00:00:00.000000000 Z
11
+ date: 2013-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -40,7 +40,7 @@ dependencies:
40
40
  version: '0'
41
41
  description: |-
42
42
  Pico web framework for building API-centric web applications.
43
- For Rack applications or Rack middlewares. Around 200 lines of code.
43
+ For Rack applications or Rack middlewares. Around 250 lines of code.
44
44
  email:
45
45
  - godfat (XD) godfat.org
46
46
  executables: []
@@ -99,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
99
  version: '0'
100
100
  requirements: []
101
101
  rubyforge_project:
102
- rubygems_version: 2.0.3
102
+ rubygems_version: 2.0.4
103
103
  signing_key:
104
104
  specification_version: 4
105
105
  summary: Pico web framework for building API-centric web applications.