raggi-async_sinatra 0.1.4 → 0.1.5

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.
Files changed (3) hide show
  1. data/examples/basic.ru +7 -1
  2. data/lib/sinatra/async.rb +25 -4
  3. metadata +2 -2
data/examples/basic.ru CHANGED
@@ -4,6 +4,8 @@ require 'sinatra/async'
4
4
  class AsyncTest < Sinatra::Base
5
5
  register Sinatra::Async
6
6
 
7
+ enable :show_exceptions
8
+
7
9
  aget '/' do
8
10
  body "hello async"
9
11
  end
@@ -12,6 +14,10 @@ class AsyncTest < Sinatra::Base
12
14
  EM.add_timer(n.to_i) { body { "delayed for #{n} seconds" } }
13
15
  end
14
16
 
17
+ aget '/raise' do
18
+ raise 'boom'
19
+ end
20
+
15
21
  end
16
22
 
17
- run AsyncTest.new
23
+ run AsyncTest.new
data/lib/sinatra/async.rb CHANGED
@@ -57,11 +57,32 @@ module Sinatra #:nodoc:
57
57
  def ahead(path, opts={}, &bk); aroute 'HEAD', path, opts, &bk; end
58
58
 
59
59
  private
60
- def aroute(*args, &block) #:nodoc:
61
- self.send :route, *args do |*bargs|
60
+ def aroute(verb, path, opts = {}, &block) #:nodoc:
61
+ route(verb, path, opts) do |*bargs|
62
+ method = "A#{verb} #{path}".to_sym
63
+
62
64
  mc = class << self; self; end
63
- mc.send :define_method, :__async_callback, &block
64
- EM.next_tick { send(:__async_callback, *bargs) }
65
+ mc.send :define_method, method, &block
66
+ mc.send :alias_method, :__async_callback, method
67
+
68
+ EM.next_tick {
69
+ begin
70
+ send(:__async_callback, *bargs)
71
+ rescue ::Exception => boom
72
+ if options.show_exceptions?
73
+ # HACK: handle_exception! re-raises the exception if show_exceptions?,
74
+ # so we ignore any errors and instead create a ShowExceptions page manually
75
+ handle_exception!(boom) rescue nil
76
+ s, h, b = Sinatra::ShowExceptions.new(proc{ raise boom }).call(request.env)
77
+ response.status = s
78
+ response.headers.replace(h)
79
+ body(b)
80
+ else
81
+ body(handle_exception!(boom))
82
+ end
83
+ end
84
+ }
85
+
65
86
  throw :async
66
87
  end
67
88
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: raggi-async_sinatra
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Tucker
@@ -65,7 +65,7 @@ files:
65
65
  - Rakefile
66
66
  - examples/basic.ru
67
67
  - lib/sinatra/async.rb
68
- has_rdoc: true
68
+ has_rdoc: false
69
69
  homepage: http://libraggi.rubyforge.org/async_sinatra
70
70
  post_install_message:
71
71
  rdoc_options: