async_sinatra 0.1.3 → 0.1.4

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.
data/README.rdoc CHANGED
@@ -19,7 +19,7 @@ A quick example:
19
19
  require 'sinatra/async'
20
20
 
21
21
  class AsyncTest < Sinatra::Base
22
- include Sinatra::Async
22
+ register Sinatra::Async
23
23
 
24
24
  aget '/' do
25
25
  body "hello async"
data/examples/basic.ru CHANGED
@@ -1,9 +1,8 @@
1
1
  #!/usr/bin/env rackup -Ilib:../lib -s thin
2
- require 'sinatra'
3
2
  require 'sinatra/async'
4
3
 
5
4
  class AsyncTest < Sinatra::Base
6
- include Sinatra::Async
5
+ register Sinatra::Async
7
6
 
8
7
  aget '/' do
9
8
  body "hello async"
data/lib/sinatra/async.rb CHANGED
@@ -1,11 +1,9 @@
1
- require 'sinatra'
1
+ require 'sinatra/base'
2
2
 
3
3
  module Sinatra #:nodoc:
4
4
 
5
- # See Async::ClassMethods for the DSL
6
- #
7
- # Normally Sinatra::Base expects that the completion of a request is
8
- # determined by the block exiting, and returning a value for the body.
5
+ # Normally Sinatra expects that the completion of a request is # determined
6
+ # by the block exiting, and returning a value for the body.
9
7
  #
10
8
  # In an async environment, we want to tell the webserver that we're not going
11
9
  # to provide a response now, but some time in the future.
@@ -25,7 +23,7 @@ module Sinatra #:nodoc:
25
23
  # require 'sinatra/async'
26
24
  #
27
25
  # class AsyncTest < Sinatra::Base
28
- # include Sinatra::Async
26
+ # register Sinatra::Async
29
27
  #
30
28
  # aget '/' do
31
29
  # body "hello async"
@@ -37,50 +35,50 @@ module Sinatra #:nodoc:
37
35
  #
38
36
  # end
39
37
  module Async
40
- module ClassMethods
41
- # Similar to Sinatra::Base#get, but the block will be scheduled to run
42
- # during the next tick of the EventMachine reactor. In the meantime,
43
- # Thin will hold onto the client connection, awaiting a call to
44
- # Async#body with the response.
45
- def aget(path, opts={}, &block)
46
- conditions = @conditions.dup
47
- aroute('GET', path, opts, &block)
38
+ # Similar to Sinatra::Base#get, but the block will be scheduled to run
39
+ # during the next tick of the EventMachine reactor. In the meantime,
40
+ # Thin will hold onto the client connection, awaiting a call to
41
+ # Async#body with the response.
42
+ def aget(path, opts={}, &block)
43
+ conditions = @conditions.dup
44
+ aroute('GET', path, opts, &block)
48
45
 
49
- @conditions = conditions
50
- aroute('HEAD', path, opts, &block)
51
- end
46
+ @conditions = conditions
47
+ aroute('HEAD', path, opts, &block)
48
+ end
52
49
 
53
- # See #aget.
54
- def aput(path, opts={}, &bk); aroute 'PUT', path, opts, &bk; end
55
- # See #aget.
56
- def apost(path, opts={}, &bk); aroute 'POST', path, opts, &bk; end
57
- # See #aget.
58
- def adelete(path, opts={}, &bk); aroute 'DELETE', path, opts, &bk; end
59
- # See #aget.
60
- def ahead(path, opts={}, &bk); aroute 'HEAD', path, opts, &bk; end
50
+ # See #aget.
51
+ def aput(path, opts={}, &bk); aroute 'PUT', path, opts, &bk; end
52
+ # See #aget.
53
+ def apost(path, opts={}, &bk); aroute 'POST', path, opts, &bk; end
54
+ # See #aget.
55
+ def adelete(path, opts={}, &bk); aroute 'DELETE', path, opts, &bk; end
56
+ # See #aget.
57
+ def ahead(path, opts={}, &bk); aroute 'HEAD', path, opts, &bk; end
61
58
 
62
- private
63
- def aroute(*args, &block) #:nodoc:
64
- self.send :route, *args do |*bargs|
65
- mc = class << self; self; end
66
- mc.send :define_method, :__async_callback, &block
67
- EM.next_tick { send(:__async_callback, *bargs) }
68
- throw :async
69
- end
59
+ private
60
+ def aroute(*args, &block) #:nodoc:
61
+ self.send :route, *args do |*bargs|
62
+ mc = class << self; self; end
63
+ mc.send :define_method, :__async_callback, &block
64
+ EM.next_tick { send(:__async_callback, *bargs) }
65
+ throw :async
70
66
  end
71
67
  end
72
68
 
73
- def self.included(klass) #:nodoc:
74
- klass.extend ClassMethods
69
+ module Helpers
70
+ # Send the given body or block as the final response to the asynchronous
71
+ # request.
72
+ def body(*args, &blk)
73
+ super
74
+ request.env['async.callback'][
75
+ [response.status, response.headers, response.body]
76
+ ] if respond_to?(:__async_callback)
77
+ end
75
78
  end
76
79
 
77
- # Send the given body or block as the final response to the asynchronous
78
- # request.
79
- def body(*args, &blk)
80
- super
81
- request.env['async.callback'][
82
- [response.status, response.headers, response.body]
83
- ] if respond_to?(:__async_callback)
80
+ def self.registered(app) #:nodoc:
81
+ app.helpers Helpers
84
82
  end
85
83
  end
86
84
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async_sinatra
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Tucker