angelo 0.2.4 → 0.3.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 +4 -4
- data/CHANGELOG.md +12 -0
- data/lib/angelo/base.rb +42 -28
- data/lib/angelo/minitest/helpers.rb +4 -1
- data/lib/angelo/server.rb +7 -3
- data/lib/angelo/version.rb +1 -1
- data/test/angelo_spec.rb +69 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ebbf63326421673b1352e779ea177d5f7b43c610
|
|
4
|
+
data.tar.gz: c1e169dd0f1d88a64bdc70df502edd24533a187d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 823587abc0ddec2fd5ffd496feb3c0295f5aa331882bad9314895a329d487ab7c823aa106b617fe447e135bf73ba50e9a0eb2ccebaa4c958590e441af60bba2f
|
|
7
|
+
data.tar.gz: e6972e20b9b724331d0873b809e8ebb7f5dbbb571ddd59e1694c56083ef7fcd5d49a4d755a4c4b90986af819bbddbb58648ecfeb714f80752055b1070b10c66a
|
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
changelog
|
|
2
2
|
=========
|
|
3
3
|
|
|
4
|
+
### 0.3.0 10 nov 2014
|
|
5
|
+
|
|
6
|
+
thanks: @mighe
|
|
7
|
+
|
|
8
|
+
* refactor bind address, port, log level and error reporting setting into top level DSLish methods
|
|
9
|
+
* set bind address with `addr '0.0.0.0'`
|
|
10
|
+
* set bind port with `port 4567`
|
|
11
|
+
* set log level with `log_level ::Logger::DEBUG`
|
|
12
|
+
* set error reporting with `report_errors!`
|
|
13
|
+
* bind address and port can still be specified on `.run` or `.run!` calls
|
|
14
|
+
* remove command line option parsing completely
|
|
15
|
+
|
|
4
16
|
### 0.2.4 4 nov 2014 totally voted
|
|
5
17
|
|
|
6
18
|
thanks: @mighe
|
data/lib/angelo/base.rb
CHANGED
|
@@ -6,23 +6,7 @@ module Angelo
|
|
|
6
6
|
|
|
7
7
|
extend Forwardable
|
|
8
8
|
def_delegators :@responder, :content_type, :headers, :redirect, :request, :transfer_encoding
|
|
9
|
-
def_delegators :@klass, :
|
|
10
|
-
|
|
11
|
-
@@addr = DEFAULT_ADDR
|
|
12
|
-
@@port = DEFAULT_PORT
|
|
13
|
-
|
|
14
|
-
@@ping_time = DEFAULT_PING_TIME
|
|
15
|
-
@@log_level = DEFAULT_LOG_LEVEL
|
|
16
|
-
|
|
17
|
-
@@report_errors = false
|
|
18
|
-
|
|
19
|
-
if ARGV.any? and not Kernel.const_defined?('Minitest')
|
|
20
|
-
require 'optparse'
|
|
21
|
-
OptionParser.new { |op|
|
|
22
|
-
op.on('-p port', 'set the port (default is 4567)') { |val| @@port = Integer(val) }
|
|
23
|
-
op.on('-o addr', "set the host (default is #{@@addr})") { |val| @@addr = val }
|
|
24
|
-
}.parse!(ARGV.dup)
|
|
25
|
-
end
|
|
9
|
+
def_delegators :@klass, :report_errors?, :sse_event, :sse_message, :sses, :websockets
|
|
26
10
|
|
|
27
11
|
attr_accessor :responder
|
|
28
12
|
|
|
@@ -40,6 +24,12 @@ module Angelo
|
|
|
40
24
|
#
|
|
41
25
|
subclass.class_eval 'class RequestError < Angelo::RequestError; end'
|
|
42
26
|
|
|
27
|
+
subclass.addr DEFAULT_ADDR
|
|
28
|
+
subclass.port DEFAULT_PORT
|
|
29
|
+
|
|
30
|
+
subclass.ping_time DEFAULT_PING_TIME
|
|
31
|
+
subclass.log_level DEFAULT_LOG_LEVEL
|
|
32
|
+
|
|
43
33
|
class << subclass
|
|
44
34
|
|
|
45
35
|
def root
|
|
@@ -60,6 +50,34 @@ module Angelo
|
|
|
60
50
|
|
|
61
51
|
end
|
|
62
52
|
|
|
53
|
+
def addr a = nil
|
|
54
|
+
@addr = a if a
|
|
55
|
+
@addr
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def log_level ll = nil
|
|
59
|
+
@log_level = ll if ll
|
|
60
|
+
@log_level
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def ping_time pt = nil
|
|
64
|
+
@ping_time = pt if pt
|
|
65
|
+
@ping_time
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def port p = nil
|
|
69
|
+
@port = p if p
|
|
70
|
+
@port
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def report_errors!
|
|
74
|
+
@report_errors = true
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def report_errors?
|
|
78
|
+
!!@report_errors
|
|
79
|
+
end
|
|
80
|
+
|
|
63
81
|
def compile! name, &block
|
|
64
82
|
define_method name, &block
|
|
65
83
|
method = instance_method name
|
|
@@ -144,13 +162,13 @@ module Angelo
|
|
|
144
162
|
Responder.content_type type
|
|
145
163
|
end
|
|
146
164
|
|
|
147
|
-
def run!
|
|
148
|
-
run
|
|
165
|
+
def run! _addr = addr, _port = port
|
|
166
|
+
run _addr, _port, true
|
|
149
167
|
end
|
|
150
168
|
|
|
151
|
-
def run
|
|
152
|
-
Celluloid.logger.level =
|
|
153
|
-
@server = Angelo::Server.new self,
|
|
169
|
+
def run _addr = addr, _port = port, blocking = false
|
|
170
|
+
Celluloid.logger.level = log_level
|
|
171
|
+
@server = Angelo::Server.new self, _addr, _port
|
|
154
172
|
@server.async.ping_websockets
|
|
155
173
|
if blocking
|
|
156
174
|
trap "INT" do
|
|
@@ -226,7 +244,7 @@ module Angelo
|
|
|
226
244
|
end
|
|
227
245
|
|
|
228
246
|
task :ping_websockets do
|
|
229
|
-
every(
|
|
247
|
+
every(@base.ping_time) do
|
|
230
248
|
websockets.all_each do |ws|
|
|
231
249
|
ws.socket << ::WebSocket::Message.ping.to_data
|
|
232
250
|
end
|
|
@@ -238,7 +256,7 @@ module Angelo
|
|
|
238
256
|
block[socket]
|
|
239
257
|
rescue Reel::SocketError, IOError, SystemCallError => e
|
|
240
258
|
# probably closed on client
|
|
241
|
-
warn e.message if
|
|
259
|
+
warn e.message if report_errors
|
|
242
260
|
socket.close unless socket.closed?
|
|
243
261
|
rescue => e
|
|
244
262
|
error e.inspect
|
|
@@ -298,10 +316,6 @@ module Angelo
|
|
|
298
316
|
halt 200, :sse
|
|
299
317
|
end
|
|
300
318
|
|
|
301
|
-
def report_errors?
|
|
302
|
-
@@report_errors
|
|
303
|
-
end
|
|
304
|
-
|
|
305
319
|
def sleep time
|
|
306
320
|
Celluloid.sleep time
|
|
307
321
|
end
|
|
@@ -13,7 +13,10 @@ module Angelo
|
|
|
13
13
|
|
|
14
14
|
before do
|
|
15
15
|
app = Class.new Angelo::Base
|
|
16
|
-
|
|
16
|
+
|
|
17
|
+
app.class_eval { content_type :html } # reset
|
|
18
|
+
Celluloid.logger.level = ::Logger::ERROR # see spec_helper.rb:9
|
|
19
|
+
|
|
17
20
|
app.class_eval &block
|
|
18
21
|
@server = Angelo::Server.new app
|
|
19
22
|
app.server = @server
|
data/lib/angelo/server.rb
CHANGED
|
@@ -9,11 +9,15 @@ module Angelo
|
|
|
9
9
|
|
|
10
10
|
def_delegators :@base, :websockets, :sses
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
attr_reader :base
|
|
13
|
+
|
|
14
|
+
def initialize base, addr = nil, port = nil
|
|
13
15
|
@base = base
|
|
16
|
+
addr ||= @base.addr
|
|
17
|
+
port ||= @base.port
|
|
14
18
|
info "Angelo #{VERSION}"
|
|
15
|
-
info "listening on #{
|
|
16
|
-
super
|
|
19
|
+
info "listening on #{addr}:#{port}"
|
|
20
|
+
super addr, port, &method(:on_connection)
|
|
17
21
|
end
|
|
18
22
|
|
|
19
23
|
def on_connection connection
|
data/lib/angelo/version.rb
CHANGED
data/test/angelo_spec.rb
CHANGED
|
@@ -442,4 +442,73 @@ describe Angelo::Base do
|
|
|
442
442
|
|
|
443
443
|
end
|
|
444
444
|
|
|
445
|
+
describe 'dsl configs' do
|
|
446
|
+
|
|
447
|
+
describe 'addr' do
|
|
448
|
+
|
|
449
|
+
define_app do
|
|
450
|
+
addr '0.0.0.0'
|
|
451
|
+
get('/'){ 'hi' }
|
|
452
|
+
end
|
|
453
|
+
|
|
454
|
+
it 'binds to the specified addr' do
|
|
455
|
+
->{ TCPServer.new '0.0.0.0', 4567 }.must_raise Errno::EADDRINUSE
|
|
456
|
+
end
|
|
457
|
+
|
|
458
|
+
end
|
|
459
|
+
|
|
460
|
+
describe 'port' do
|
|
461
|
+
|
|
462
|
+
define_app do
|
|
463
|
+
port 3000
|
|
464
|
+
get('/'){ 'hi' }
|
|
465
|
+
end
|
|
466
|
+
|
|
467
|
+
it 'binds to the specified port' do
|
|
468
|
+
->{ TCPServer.new Angelo::DEFAULT_ADDR, 3000 }.must_raise Errno::EADDRINUSE
|
|
469
|
+
end
|
|
470
|
+
|
|
471
|
+
end
|
|
472
|
+
|
|
473
|
+
describe 'log_level' do
|
|
474
|
+
|
|
475
|
+
define_app do
|
|
476
|
+
log_level Logger::FATAL
|
|
477
|
+
get('/'){ 'hi' }
|
|
478
|
+
end
|
|
479
|
+
|
|
480
|
+
it 'sets the logging level' do
|
|
481
|
+
@server.base.log_level.must_equal Logger::FATAL
|
|
482
|
+
end
|
|
483
|
+
|
|
484
|
+
end
|
|
485
|
+
|
|
486
|
+
describe 'ping_time' do
|
|
487
|
+
|
|
488
|
+
define_app do
|
|
489
|
+
ping_time 3
|
|
490
|
+
get('/'){ 'hi' }
|
|
491
|
+
end
|
|
492
|
+
|
|
493
|
+
it 'sets the websocket ping time' do
|
|
494
|
+
@server.base.ping_time.must_equal 3
|
|
495
|
+
end
|
|
496
|
+
|
|
497
|
+
end
|
|
498
|
+
|
|
499
|
+
describe 'report_errors!' do
|
|
500
|
+
|
|
501
|
+
define_app do
|
|
502
|
+
report_errors!
|
|
503
|
+
get('/'){ 'hi' }
|
|
504
|
+
end
|
|
505
|
+
|
|
506
|
+
it 'sets flag for reporting error traces in the log' do
|
|
507
|
+
assert @server.base.report_errors?
|
|
508
|
+
end
|
|
509
|
+
|
|
510
|
+
end
|
|
511
|
+
|
|
512
|
+
end
|
|
513
|
+
|
|
445
514
|
end
|
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.
|
|
4
|
+
version: 0.3.0
|
|
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-11-
|
|
11
|
+
date: 2014-11-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: reel
|