cramp 0.15.2 → 0.15.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YTU3MzczMjYwZmVjOWNlODI4MDViMDkzODFkYmRlNTI2ZGFmY2E3Yw==
4
+ ZTExZGJiNmFkNjk5NmM0NDgwMzUwYTJkMjdlZDEwMGEzYjc3ODFiMg==
5
5
  data.tar.gz: !binary |-
6
- ZmExZWQwMTJiMGRkMTNjZWVlNmJlY2FhZmNmNjNjYTMzMWFhZWI0ZA==
6
+ N2I5NDY5OTJiZjE1ZTkwZmUwZDU5YmY4MjU1Yzg3ZGYwMDdhNzExYQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YjM0NjdiMDZjOWI0ZWZiMjBkMzg5ZDgwYWRhZWRiMjBjYjlhNTQwNGM2ODk3
10
- ZmI4NzNhM2IyNmZjODBhMDIwNmZkODFjMTdhZmI0YWJjNTBmMzMyNzAwNzc2
11
- NzJmOTMyMWEzZmI4OGNhOTEzZmM0MWQxODYyZWNmMjM1NmE4MjU=
9
+ YjQ1YjE4YzQ1MDkzM2Y1MmYyZmJmY2JmYjE3NTdhMTJhMDE3YmZjNDFiMzQw
10
+ NWRhYjI3MmYyZDdlYTc2N2RiY2Y2MzZmZDIzMGJjYWFkMTJlN2JiODc2ZDkz
11
+ MmYwN2ViNjQzNTVhNTE5YjU2YmZiZDE2NjQxMTIzNzRiZDg0NzA=
12
12
  data.tar.gz: !binary |-
13
- MjA5NjZmN2I5NDAyNTNkYWM1YWU1NDliZTkwYzJlY2NlZTI5MzBhYmMzYzgz
14
- ZmE4MzRlYTk0N2U5MThhNmFkZmY4YTlkYzlhMmUwZmE4YjVlOWQ1YmIyZGY0
15
- MDM1ZDFjZTIyOTRmZGU1MmE5NzcwNDQwODQyYmFhZjQ2YTE5NTk=
13
+ OTgyYTE3OTgwZDc3MmYzZTY2NjI2NTY4M2RlZDg4ZDBmMzA5MDY2ODE0ZTk5
14
+ ZmM2MWM1OTllM2VhNGY0MTk4MjcyMDdiMzFlNTBhMTFhYmQwNzQ0YmI0NzYx
15
+ NzkzNWUzNTU1MmYyMDgxMjM4YjAyN2FjMDIwM2VjNjRjZjAzMTk=
@@ -26,7 +26,7 @@ module Cramp
26
26
  throw :async
27
27
  end
28
28
 
29
- protected
29
+ private
30
30
 
31
31
  def continue
32
32
  init_async_body
@@ -75,7 +75,7 @@ module Cramp
75
75
  end
76
76
 
77
77
  def halt(status, headers = {}, halt_body = '')
78
- send_response(status, headers, halt_body)
78
+ send_response(status, headers, [halt_body])
79
79
  end
80
80
 
81
81
  def send_response(response_status, response_headers, response_body)
@@ -94,8 +94,6 @@ module Cramp
94
94
  @env['router.params'] || {}
95
95
  end
96
96
 
97
- private
98
-
99
97
  def is_finishable?
100
98
  !finished? && @body && !@body.closed?
101
99
  end
@@ -5,7 +5,7 @@ module Cramp
5
5
 
6
6
  def initialize(env)
7
7
  super
8
-
8
+
9
9
  case
10
10
  when Faye::EventSource.eventsource?(env)
11
11
  # request has Accept: text/event-stream
@@ -24,7 +24,7 @@ module Cramp
24
24
  end
25
25
  end
26
26
 
27
- protected
27
+ private
28
28
 
29
29
  def render(body, *args)
30
30
  send(:"render_#{transport}", body, *args)
@@ -119,8 +119,6 @@ module Cramp
119
119
  string.respond_to?(:force_encoding) ? string.force_encoding(encoding) : string
120
120
  end
121
121
 
122
- protected
123
-
124
122
  def finish
125
123
  case transport
126
124
  when :chunked
@@ -62,7 +62,21 @@ module Cramp
62
62
  end
63
63
  end
64
64
 
65
- protected
65
+ private
66
+
67
+ def _receive_protocol10_data(data)
68
+ protocol10_parser.data << data
69
+
70
+ messages = @protocol10_parser.process_data
71
+ messages.each do |type, content|
72
+ _invoke_data_callbacks(content) if type == :text
73
+ end
74
+ end
75
+
76
+ def _receive_protocol76_data(data)
77
+ data = data.split(Regexp.new('\000([^\377]*)\377')).select{|d| !d.empty? }.collect{|d| d.gsub(Regexp.new('^\x00|\xff$'), '') }
78
+ data.each {|message| _invoke_data_callbacks(message) }
79
+ end
66
80
 
67
81
  def _invoke_data_callbacks(message)
68
82
  self.class.on_data_callbacks.each do |callback|
@@ -74,10 +88,8 @@ module Cramp
74
88
  handler = ExceptionHandler.new(@env, exception)
75
89
 
76
90
  # Log the exception
77
- unless ENV['RACK_ENV'] == 'test'
78
- exception_body = handler.dump_exception
79
- Cramp.logger ? Cramp.logger.error(exception_body) : $stderr.puts(exception_body)
80
- end
91
+ exception_body = handler.dump_exception
92
+ Cramp.logger ? Cramp.logger.error(exception_body) : $stderr.puts(exception_body)
81
93
 
82
94
  case @_state
83
95
  when :init
@@ -66,7 +66,7 @@ module Cramp
66
66
  end
67
67
  end
68
68
 
69
- protected
69
+ private
70
70
 
71
71
  def active_record?
72
72
  options[:with_active_record]
@@ -94,4 +94,4 @@ module Cramp
94
94
  end
95
95
 
96
96
  end
97
- end
97
+ end
@@ -1,4 +1,4 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gem 'cramp'
4
4
 
@@ -14,11 +14,11 @@ module <%= app_const_base %>
14
14
  end
15
15
 
16
16
  def self.routes
17
- @_routes ||= eval(File.read('./config/routes.rb'))
17
+ @_routes ||= eval(File.read(File.expand_path('../config/routes.rb', __FILE__)))
18
18
  end
19
19
 
20
20
  <% if active_record? %>def self.database_config
21
- @_database_config ||= YAML.load(File.read('./config/database.yml')).with_indifferent_access
21
+ @_database_config ||= YAML.load_file(File.expand_path('../config/database.yml', __FILE__)).with_indifferent_access
22
22
  end
23
23
 
24
24
  <% end %># Initialize the application
@@ -33,4 +33,4 @@ end
33
33
  Bundler.require(:default, <%= app_const %>.env)
34
34
 
35
35
  # Preload application classes
36
- Dir['./app/**/*.rb'].each {|f| require f}
36
+ Dir[File.join(File.dirname(__FILE__), 'app/**/*.rb')].each {| f| require f }
@@ -1,4 +1,4 @@
1
- require './application'
1
+ require File.expand_path('../application', __FILE__)
2
2
  <%= app_const %>.initialize!
3
3
 
4
4
  # Development middlewares
@@ -19,7 +19,7 @@ module Cramp
19
19
  @timers = []
20
20
  end
21
21
 
22
- protected
22
+ private
23
23
 
24
24
  def continue
25
25
  super
@@ -10,33 +10,59 @@ module Cramp
10
10
  @request = Rack::MockRequest.new(app)
11
11
  end
12
12
 
13
- def get(path, options = {}, headers = {}, &block)
13
+ def get(path, opts={}, headers={}, &block) request(:get, path, opts, headers, &block) end
14
+ def post(path, opts={}, headers={}, &block) request(:post, path, opts, headers, &block) end
15
+ def put(path, opts={}, headers={}, &block) request(:put, path, opts, headers, &block) end
16
+ def delete(path, opts={}, headers={}, &block) request(:delete, path, opts, headers, &block) end
17
+ def options(path, opts={}, headers={}, &block) request(:options, path, opts, headers, &block) end
18
+
19
+ def request(method, path, options = {}, headers = {}, &block)
14
20
  callback = options.delete(:callback) || block
15
21
  headers = headers.merge('async.callback' => callback)
16
22
 
17
23
  EM.run do
18
- catch(:async) { @request.get(path, headers) }
24
+ catch(:async) { @request.request(method, path, headers) }
19
25
  end
20
26
  end
21
27
 
22
- def get_body(path, options = {}, headers = {}, &block)
28
+ def get_body(path, opts={}, headers={}, &block) request_body(:get, path, opts, headers, &block) end
29
+ def post_body(path, opts={}, headers={}, &block) request_body(:post, path, opts, headers, &block) end
30
+ def put_body(path, opts={}, headers={}, &block) request_body(:put, path, opts, headers, &block) end
31
+ def delete_body(path, opts={}, headers={}, &block) request_body(:delete, path, opts, headers, &block) end
32
+ def options_body(path, opts={}, headers={}, &block) request_body(:options, path, opts, headers, &block) end
33
+
34
+ def request_body(method, path, options = {}, headers = {}, &block)
23
35
  callback = options.delete(:callback) || block
24
- response_callback = proc {|response| response[-1].each {|chunk| callback.call(chunk) } }
36
+ response_callback = proc do |response|
37
+ # 'halt' returns a String, not an async Body object
38
+ if response.last.is_a? String
39
+ callback.call(response.last)
40
+ else
41
+ response.last.each {|chunk| callback.call(chunk) }
42
+ end
43
+ end
25
44
  headers = headers.merge('async.callback' => response_callback)
26
45
 
27
46
  EM.run do
28
- catch(:async) { @request.get(path, headers) }
47
+ catch(:async) { @request.request(method, path, headers) }
29
48
  end
30
49
  end
31
50
 
32
- def get_body_chunks(path, options = {}, headers = {}, &block)
51
+
52
+ def get_body_chunks(path, opts={}, headers={}, &block) request_body_chunks(:get, path, opts, headers, &block) end
53
+ def post_body_chunks(path, opts={}, headers={}, &block) request_body_chunks(:post, path, opts, headers, &block) end
54
+ def put_body_chunks(path, opts={}, headers={}, &block) request_body_chunks(:put, path, opts, headers, &block) end
55
+ def delete_body_chunks(path, opts={}, headers={}, &block) request_body_chunks(:delete, path, opts, headers, &block) end
56
+ def options_body_chunks(path, opts={}, headers={}, &block) request_body_chunks(:options, path, opts, headers, &block) end
57
+
58
+ def request_body_chunks(method, path, options = {}, headers = {}, &block)
33
59
  callback = options.delete(:callback) || block
34
60
  count = options.delete(:count) || 1
35
61
 
36
62
  stopping = false
37
63
  chunks = []
38
64
 
39
- get_body(path, options, headers) do |body_chunk|
65
+ request_body(method, path, options, headers) do |body_chunk|
40
66
  chunks << body_chunk unless stopping
41
67
 
42
68
  if chunks.count >= count
@@ -55,4 +81,5 @@ module Cramp
55
81
  EM.stop
56
82
  end
57
83
  end
58
- end
84
+ end
85
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cramp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.2
4
+ version: 0.15.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pratik Naik
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-16 00:00:00.000000000 Z
12
+ date: 2014-04-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -115,7 +115,8 @@ files:
115
115
  - lib/vendor/fiber_pool.rb
116
116
  - bin/cramp
117
117
  homepage: http://cramp.in
118
- licenses: []
118
+ licenses:
119
+ - MIT
119
120
  metadata: {}
120
121
  post_install_message:
121
122
  rdoc_options: []
@@ -133,8 +134,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
134
  version: '0'
134
135
  requirements: []
135
136
  rubyforge_project:
136
- rubygems_version: 2.1.9
137
+ rubygems_version: 2.1.11
137
138
  signing_key:
138
139
  specification_version: 4
139
140
  summary: Asynchronous web framework.
140
141
  test_files: []
142
+ has_rdoc: false