angelo 0.2.2 → 0.2.3

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: dd2cb610a7377a13e931101270360afe324e1abd
4
- data.tar.gz: 079ed6a36ff484e41ca11fdd7a1791a874923904
3
+ metadata.gz: 8b18b8a96ef58b0f38df32ae070d22da0564b2f1
4
+ data.tar.gz: c1abdf8b2494da8b8fc0b3efcce12bc5fe2ea06e
5
5
  SHA512:
6
- metadata.gz: c6e24a7a88a9b44361c0efebb43ee3fb58130c19280cf3c73b013748ab87b76d104d85b0bd93416b7577c6504680550cfb5f77c8d2be9a38d3c7865eec9f250d
7
- data.tar.gz: 543e9def3af8a7d149a8ce17bd1a15702a88a807949a1584f1e58f34815921fd5c2446c1b0ea536d3743156ea62e3ceb493b2235263438e3b5447fc109f1043e
6
+ metadata.gz: a561e6343ed0ac67eac30d741b8c65421b684936d1761f2aeb08202eb7d4eecf3db78cf497823ba4ebaaa37f45e1fc742fccecc2bcf8f9c1163e309f5480173b
7
+ data.tar.gz: aa9e7a498eb39a86b0e95c0df5607fcf5b825b61159a3490ce7e2eb18ad90dde2e11058e10840c083b0b6f2b4db4ba333e8df59abac8754c840d7e2344719747
data/CHANGELOG.md CHANGED
@@ -1,6 +1,21 @@
1
1
  changelog
2
2
  =========
3
3
 
4
+ ### 0.2.3 28 oct 2014
5
+
6
+ thanks: @mighe, @chewi
7
+
8
+ * add flag (default: false) to `Base.run` to trap INT and sleep or not
9
+ * add `Base.run!` which calls `.run` with flag set true
10
+ * fix for form params keys with no values
11
+
12
+ ### 0.2.2 22 oct 2014
13
+
14
+ thanks: @chewi
15
+
16
+ * add on_close setter to EventSource
17
+ * fix peeraddr forward on EventSource
18
+
4
19
  ### 0.2.1 7 oct 2014
5
20
 
6
21
  thanks: @chewi
data/README.md CHANGED
@@ -63,7 +63,8 @@ from inside a websocket handler block. These can "later" be iterated over so one
63
63
  emit a message on every connected websocket when the service receives a POST request.
64
64
 
65
65
  The `websockets` helper also includes a context ability, so you can stash connected websocket clients
66
- into different "sections".
66
+ into different "sections". Also, by default, the helper will `reject!` any closed sockets before
67
+ returning; you may optionally pass `false` to the helper to skip this step.
67
68
 
68
69
  ##### Example!
69
70
 
@@ -178,10 +179,12 @@ Angelo also includes a "stash" helper for SSE connections. One can `<<` a socket
178
179
  inside an `eventsource` handler block. These can also be "later" be iterated over so one can do things
179
180
  like emit a message on every SSE connection when the service receives a POST request.
180
181
 
181
- The `sses` helper includes the same a context ability as the `websockets` helper. In addition, the
182
- `sses` stash includes methods for easily sending events or messages to all stashed connections. **Note
183
- that the `Stash::SSE#event` method only works on non-default contexts and uses the context name as
184
- the event name.**
182
+ The `sses` helper includes the same a context ability as the `websockets` helper. Also, by default,
183
+ the helper will `reject!` any closed sockets before returning, just like `websockets`. You may
184
+ optionally pass `false` to the helper to skip this step.In addition, the `sses` stash includes
185
+ methods for easily sending events or messages to all stashed connections. **Note that the
186
+ `Stash::SSE#event` method only works on non-default contexts and uses the context name as the event
187
+ name.**
185
188
 
186
189
  ```ruby
187
190
  eventsource '/sse' do |s|
@@ -222,6 +225,37 @@ Handling this on the client may require conditionals for [browsers](http://caniu
222
225
  do not support EventSource yet, since this will respond with a non-"text/event-stream" Content-Type if
223
226
  'sse' is not present in the params.
224
227
 
228
+ ##### `EventSource#on_close` helper
229
+
230
+ When inside an eventsource block, you can use may want to do something specific when a client closes the
231
+ connection. For this case, there are `on_close` and `on_close=` methods on the object passed to the block
232
+ that will get called if the client closes the socket. The assignment method takes a proc object and the
233
+ other one takes a block:
234
+
235
+ ```ruby
236
+ get '/' do
237
+ eventsource do |es|
238
+
239
+ # assignment!
240
+ es.on_close = ->{sses(false).remove_socket es}
241
+
242
+ sses << es
243
+ end
244
+ end
245
+
246
+ eventsource '/sse' do |es|
247
+
248
+ # just passing a block here
249
+ es.on_close {sses(false).remove_socket es}
250
+
251
+ sses << es
252
+ end
253
+ ```
254
+
255
+ Note the use of the optional parameter the stashes here; by default, stash accessors (`websockets` and
256
+ `sses`) will `reject!` any closed sockets before letting you in. If you pass `false` to the stash
257
+ accessors, they will skip the `reject!` step.
258
+
225
259
  ### Tasks + Async / Future
226
260
 
227
261
  Angelo is built on Reel and Celluloid::IO, giving your web application class the ability to define
@@ -555,7 +589,7 @@ class Foo < Angelo::Base
555
589
  get '/chunky_json' do
556
590
  content_type :json
557
591
 
558
- # this helper requires a block that takes one arg, the response
592
+ # this helper requires a block that takes one arg, the response
559
593
  # proc to call with each chunk (i.e. the block that is passed to
560
594
  # `#each`)
561
595
  #
data/lib/angelo/base.rb CHANGED
@@ -144,15 +144,22 @@ module Angelo
144
144
  Responder.content_type type
145
145
  end
146
146
 
147
- def run addr = @@addr, port = @@port
147
+ def run! addr = @@addr, port = @@port
148
+ run addr, port, true
149
+ end
150
+
151
+ def run addr = @@addr, port = @@port, blocking = false
148
152
  Celluloid.logger.level = @@log_level
149
153
  @server = Angelo::Server.new self, addr, port
150
154
  @server.async.ping_websockets
151
- trap "INT" do
152
- @server.terminate if @server and @server.alive?
153
- exit
155
+ if blocking
156
+ trap "INT" do
157
+ @server.terminate if @server and @server.alive?
158
+ exit
159
+ end
160
+ sleep
154
161
  end
155
- sleep
162
+ @server
156
163
  end
157
164
 
158
165
  def local_path path
@@ -12,7 +12,6 @@ module Angelo
12
12
  AMPERSAND = '&'
13
13
 
14
14
  def parse_formencoded str
15
- raise FormEncodingError unless str.empty? or str.index EQUALS
16
15
  str.split(AMPERSAND).reduce(Responder.symhash) do |p, kv|
17
16
  key, value = kv.split(EQUALS).map {|s| CGI.unescape s}
18
17
  p[key] = value
@@ -1,3 +1,3 @@
1
1
  module Angelo
2
- VERSION = '0.2.2'
2
+ VERSION = '0.2.3'
3
3
  end
data/test/angelo_spec.rb CHANGED
@@ -327,7 +327,7 @@ describe Angelo::Base do
327
327
 
328
328
  it 'does not parse JSON body when content-type is formencoded' do
329
329
  post '/json', obj.to_json, {'Content-Type' => Angelo::FORM_TYPE}
330
- last_response.status.must_equal 400
330
+ last_response_must_be_json(obj.to_json => nil)
331
331
  end
332
332
 
333
333
  it 'does not parse body when request content-type not set' do
@@ -342,6 +342,13 @@ describe Angelo::Base do
342
342
  end
343
343
  end
344
344
 
345
+ Angelo::HTTPABLE.each do |m|
346
+ it "does not choke on #{m.to_s.upcase} requests with without param values" do
347
+ send m, '/json?foo'
348
+ last_response_must_be_json('foo' => nil)
349
+ end
350
+ end
351
+
345
352
  end
346
353
 
347
354
  describe 'request_headers helper' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: angelo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenichi Nakamura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-22 00:00:00.000000000 Z
11
+ date: 2014-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: reel