uv-rays 0.0.1 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3800c7d8ef446765e933dbf2f732dd037d4185f2
4
- data.tar.gz: 8cb367445a00f73ad52e16ab4d26dac7453c1cd6
3
+ metadata.gz: 663ee2734c50410a550b07bb2cf2e0fa868fa9a3
4
+ data.tar.gz: d268b959e9d47496538b8133fb4049c316838057
5
5
  SHA512:
6
- metadata.gz: a4812d336b5366a07b4ee4f77c888cc323a24d9f700c93ea0c0335aa7e18bc08918328ddeabd47b858ad2e6773c78ce9ebba6c4cb4a468bc449697dfd4b41b63
7
- data.tar.gz: 07285a027794ac7f3d4332595f936ea56000b251909665e4dd02edeb5e77a7b6f74fe901617883199fd07332329c48bd03ea152db7fe40ec25bfe5515e831d48
6
+ metadata.gz: bf48b38bea0a918df33883661c51906bb7aebedb51356589495827de3a67549ccb31a86f547bfed83aa85f0402ae3aebf88976e30b8fbce5058ba8f24e6466be
7
+ data.tar.gz: 91f4931a148d3219d01673253ba19c1411187477545609486a0a2f6f957d6405669363a7bcf4a534f24194364a71419ad89b2fc4401f4ed6b9a461113de37bd0
@@ -1,5 +1,5 @@
1
1
 
2
- module UvRays
2
+ module UV
3
3
 
4
4
  # AbstractTokenizer is similar to BufferedTokernizer however should
5
5
  # only be used when there is no delimiter to work with. It uses a
@@ -13,7 +13,7 @@
13
13
  # end
14
14
  # end
15
15
  # end
16
- module UvRays
16
+ module UV
17
17
  class BufferedTokenizer
18
18
 
19
19
  attr_accessor :delimiter, :indicator, :size_limit, :verbose
@@ -23,7 +23,7 @@ module UvRays
23
23
  @delimiter = options[:delimiter]
24
24
  @indicator = options[:indicator]
25
25
  @size_limit = options[:size_limit]
26
- @verbose = options[:verbose] if @size_limit
26
+ @verbose = options[:verbose] if @size_limit
27
27
 
28
28
  raise ArgumentError, 'no delimiter provided' unless @delimiter
29
29
 
@@ -1,5 +1,5 @@
1
1
 
2
- module UvRays
2
+ module UV
3
3
  def self.try_connect(tcp, handler, server, port)
4
4
  if IPAddress.valid? server
5
5
  tcp.finally handler.method(:on_close)
@@ -15,7 +15,7 @@ module UvRays
15
15
  else
16
16
  tcp.loop.lookup(server).then(
17
17
  proc { |result|
18
- UvRays.try_connect(tcp, handler, result[0][0], port)
18
+ UV.try_connect(tcp, handler, result[0][0], port)
19
19
  },
20
20
  proc { |failure|
21
21
  # TODO:: Log error on loop
@@ -75,7 +75,23 @@ module UvRays
75
75
  end
76
76
  end
77
77
 
78
- def stream_file(filename)
78
+ def stream_file(filename, type = :raw)
79
+ file = @loop.file(filename, File::RDONLY)
80
+ file.progress do # File is open and available for reading
81
+ file.send_file(@transport, type).finally do
82
+ file.close
83
+ end
84
+ end
85
+ return file
86
+ end
87
+
88
+ def keepalive(raw_time)
89
+ time = raw_time.to_i
90
+ if time.to_i <= 0
91
+ @transport.disable_keepalive
92
+ else
93
+ @transport.enable_keepalive(time)
94
+ end
79
95
  end
80
96
 
81
97
  def on_connect(transport) # user to define
@@ -111,12 +127,12 @@ module UvRays
111
127
  def initialize(server, port)
112
128
  super()
113
129
 
114
- @loop = Libuv::Loop.current
130
+ @loop = Libuv::Loop.current || Libuv::Loop.default
115
131
  @server = server
116
132
  @port = port
117
133
  @transport = @loop.tcp
118
134
 
119
- ::UvRays.try_connect(@transport, self, @server, @port)
135
+ ::UV.try_connect(@transport, self, @server, @port)
120
136
  end
121
137
 
122
138
  def use_tls(args = {})
@@ -136,7 +152,7 @@ module UvRays
136
152
  @server = server || @server
137
153
  @port = port || @port
138
154
 
139
- ::UvRays.try_connect(@transport, self, @server, @port)
155
+ ::UV.try_connect(@transport, self, @server, @port)
140
156
  end
141
157
  end
142
158
 
@@ -144,7 +160,7 @@ module UvRays
144
160
  def initialize(server = nil, port = nil)
145
161
  super()
146
162
 
147
- @loop = Libuv::Loop.current
163
+ @loop = Libuv::Loop.current || Libuv::Loop.default
148
164
  @transport = @loop.udp
149
165
  @transport.progress method(:on_read)
150
166
 
@@ -1,4 +1,4 @@
1
- module UvRays
1
+ module UV
2
2
  module Http
3
3
  module Encoding
4
4
  HTTP_REQUEST_HEADER="%s %s HTTP/1.1\r\n"
@@ -1,4 +1,4 @@
1
- module UvRays
1
+ module UV
2
2
  module Http
3
3
  class Request < ::Libuv::Q::DeferredPromise
4
4
  include Encoding
@@ -138,7 +138,7 @@ module UvRays
138
138
 
139
139
  # Set the User-Agent if it hasn't been specified
140
140
  if !head.key?('user-agent')
141
- head['user-agent'] = "UvRays HttpClient"
141
+ head['user-agent'] = "UV HttpClient"
142
142
  elsif head['user-agent'].nil?
143
143
  head.delete('user-agent')
144
144
  end
@@ -1,4 +1,4 @@
1
- module UvRays
1
+ module UV
2
2
  module Http
3
3
  class Headers < Hash
4
4
  # The HTTP version returned
@@ -52,7 +52,7 @@ module UvRays
52
52
  @chunked = false
53
53
  end
54
54
 
55
- def on_status_complete(parser)
55
+ def on_status(parser, data)
56
56
  # Different HTTP versions have different defaults
57
57
  if @state.http_minor == 0
58
58
  @close_connection = true
@@ -1,4 +1,4 @@
1
- module UvRays
1
+ module UV
2
2
  class CookieJar
3
3
  def initialize
4
4
  @jar = ::CookieJar::Jar.new
@@ -60,7 +60,7 @@ module UvRays
60
60
  uri.port ||= (@https ? 443 : 80)
61
61
 
62
62
 
63
- @loop = Libuv::Loop.current
63
+ @loop = Libuv::Loop.current || Libuv::Loop.default
64
64
  @host = uri.host
65
65
  @port = uri.port
66
66
  #@transport = @loop.tcp
@@ -196,7 +196,7 @@ module UvRays
196
196
  end
197
197
 
198
198
  @connecting = true
199
- ::UvRays.try_connect(@transport, self, @host, @port)
199
+ ::UV.try_connect(@transport, self, @host, @port)
200
200
  end
201
201
 
202
202
  def get_connection(callback = nil, &blk)
@@ -23,7 +23,7 @@
23
23
  #++
24
24
 
25
25
 
26
- module UvRays
26
+ module UV
27
27
  class Scheduler
28
28
  #
29
29
  # A 'cron line' is a line in the sense of a crontab
@@ -23,12 +23,12 @@
23
23
  #++
24
24
 
25
25
 
26
- module UvRays
26
+ module UV
27
27
  class Scheduler
28
28
 
29
29
  def self.parse_in(o, quiet = false)
30
30
  # if o is an integer we are looking at seconds
31
- o.is_a?(String) ? parse_duration(o, quiet) : (o * 1000)
31
+ o.is_a?(String) ? parse_duration(o, quiet) : o
32
32
  end
33
33
 
34
34
  TZ_REGEX = /\b((?:[a-zA-Z][a-zA-z0-9\-+]+)(?:\/[a-zA-Z0-9\-+]+)?)\b/
@@ -1,5 +1,5 @@
1
1
 
2
- module UvRays
2
+ module UV
3
3
 
4
4
  class ScheduledEvent < ::Libuv::Q::DeferredPromise
5
5
  include Comparable
@@ -161,7 +161,7 @@ module UvRays
161
161
  #
162
162
  # @param time [String] a human readable string representing the time period. 3w2d4h1m2s for example.
163
163
  # @param callback [Proc] a block or method to execute when the event triggers
164
- # @return [::UvRays::Repeat]
164
+ # @return [::UV::Repeat]
165
165
  def every(time, callback = nil, &block)
166
166
  callback ||= block
167
167
  ms = Scheduler.parse_in(time)
@@ -178,7 +178,7 @@ module UvRays
178
178
  #
179
179
  # @param time [String] a human readable string representing the time period. 3w2d4h1m2s for example.
180
180
  # @param callback [Proc] a block or method to execute when the event triggers
181
- # @return [::UvRays::OneShot]
181
+ # @return [::UV::OneShot]
182
182
  def in(time, callback = nil, &block)
183
183
  callback ||= block
184
184
  ms = @loop.now + Scheduler.parse_in(time)
@@ -195,7 +195,7 @@ module UvRays
195
195
  #
196
196
  # @param time [String, Time] a representation of a date and time that can be parsed
197
197
  # @param callback [Proc] a block or method to execute when the event triggers
198
- # @return [::UvRays::OneShot]
198
+ # @return [::UV::OneShot]
199
199
  def at(time, callback = nil, &block)
200
200
  callback ||= block
201
201
  ms = Scheduler.parse_at(time) - @time_diff
@@ -212,7 +212,7 @@ module UvRays
212
212
  #
213
213
  # @param schedule [String] a standard CRON job line.
214
214
  # @param callback [Proc] a block or method to execute when the event triggers
215
- # @return [::UvRays::Repeat]
215
+ # @return [::UV::Repeat]
216
216
  def cron(schedule, callback = nil, &block)
217
217
  callback ||= block
218
218
  ms = Scheduler.parse_cron(time)
@@ -312,7 +312,7 @@ end
312
312
  module Libuv
313
313
  class Loop
314
314
  def scheduler
315
- @scheduler ||= UvRays::Scheduler.new(@loop)
315
+ @scheduler ||= UV::Scheduler.new(@loop)
316
316
  @scheduler
317
317
  end
318
318
  end
@@ -1,5 +1,5 @@
1
1
 
2
- module UvRays
2
+ module UV
3
3
  class TcpServer < ::Libuv::TCP
4
4
  def initialize(loop, server, port, klass, *args)
5
5
  super(loop)
@@ -1,3 +1,3 @@
1
- module UvRays
2
- VERSION = '0.0.1'
1
+ module UV
2
+ VERSION = '0.2.0'
3
3
  end
data/lib/uv-rays.rb CHANGED
@@ -29,7 +29,7 @@ require 'uv-rays/http_endpoint'
29
29
 
30
30
 
31
31
 
32
- module UvRays
32
+ module UV
33
33
 
34
34
  # @private
35
35
  def self.klass_from_handler(klass, handler = nil, *args)
@@ -69,7 +69,7 @@ module UvRays
69
69
  raise ThreadError, "There is no Libuv Loop running on the current thread" if loop.nil?
70
70
 
71
71
  klass = klass_from_handler(InboundConnection, handler, *args)
72
- UvRays::TcpServer.new loop, server, port, klass, *args
72
+ UV::TcpServer.new loop, server, port, klass, *args
73
73
  end
74
74
 
75
75
  def self.attach_server(sock, handler, *args)
@@ -79,7 +79,7 @@ module UvRays
79
79
  klass = klass_from_handler(InboundConnection, handler, *args)
80
80
  sd = sock.respond_to?(:fileno) ? sock.fileno : sock
81
81
 
82
- UvRays::TcpServer.new loop, sd, sd, klass, *args
82
+ UV::TcpServer.new loop, sd, sd, klass, *args
83
83
  end
84
84
 
85
85
  def self.open_datagram_socket(handler, server = nil, port = nil, *args)
@@ -91,6 +91,3 @@ module UvRays
91
91
  end
92
92
  end
93
93
 
94
- # Alias for {UvRays}
95
- UV = UvRays
96
-
@@ -1,8 +1,8 @@
1
1
  require 'uv-rays'
2
2
 
3
- describe UvRays::AbstractTokenizer do
3
+ describe UV::AbstractTokenizer do
4
4
  before :each do
5
- @buffer = UvRays::AbstractTokenizer.new({
5
+ @buffer = UV::AbstractTokenizer.new({
6
6
  indicator: "Start",
7
7
  callback: lambda { |data|
8
8
  return 4 if data.length > 3
@@ -16,29 +16,29 @@ describe UvRays::AbstractTokenizer do
16
16
  msg1 = "test"
17
17
 
18
18
  result = @buffer.extract(msg1)
19
- result.should == []
19
+ expect(result).to eq([])
20
20
  end
21
21
 
22
22
  it "should not return anything when an empty message is present" do
23
23
  msg1 = "test"
24
24
 
25
25
  result = @buffer.extract(msg1)
26
- result.should == []
26
+ expect(result).to eq([])
27
27
  end
28
28
 
29
29
  it "should tokenize messages where the data is a complete message" do
30
30
  msg1 = "Start1234"
31
31
 
32
32
  result = @buffer.extract(msg1)
33
- result.should == ['1234']
33
+ expect(result).to eq(['1234'])
34
34
  end
35
35
 
36
36
  it "should return multiple complete messages" do
37
37
  msg1 = "Start1234Start123456"
38
38
 
39
39
  result = @buffer.extract(msg1)
40
- result.should == ['1234', '1234']
41
- @buffer.flush.should == '56' # as we've indicated a message length of 4
40
+ expect(result).to eq(['1234', '1234'])
41
+ expect(@buffer.flush).to eq('56') # as we've indicated a message length of 4
42
42
  end
43
43
 
44
44
  it "should tokenize messages where the indicator is split" do
@@ -46,32 +46,32 @@ describe UvRays::AbstractTokenizer do
46
46
  msg2 = "twhoaStart1234"
47
47
 
48
48
  result = @buffer.extract(msg1)
49
- result.should == []
49
+ expect(result).to eq([])
50
50
  result = @buffer.extract(msg2)
51
- result.should == ['whoa', '1234']
51
+ expect(result).to eq(['whoa', '1234'])
52
52
 
53
53
  msg1 = "123Star"
54
54
  msg2 = "twhoaSt"
55
55
  msg3 = "art1234"
56
56
 
57
57
  result = @buffer.extract(msg1)
58
- result.should == []
58
+ expect(result).to eq([])
59
59
  result = @buffer.extract(msg2)
60
- result.should == ['whoa']
60
+ expect(result).to eq(['whoa'])
61
61
  result = @buffer.extract(msg3)
62
- result.should == ['1234']
62
+ expect(result).to eq(['1234'])
63
63
  end
64
64
 
65
65
  it "should empty the buffer if the limit is exceeded" do
66
66
  result = @buffer.extract('1234567890G')
67
- result.should == []
67
+ expect(result).to eq([])
68
68
 
69
69
  # We keep enough to match a possible partial indicator
70
- @buffer.flush.should == '890G'
70
+ expect(@buffer.flush).to eq('890G')
71
71
  end
72
72
 
73
73
  it "should work with regular expressions" do
74
- @buffer = UvRays::AbstractTokenizer.new({
74
+ @buffer = UV::AbstractTokenizer.new({
75
75
  indicator: /Start/i,
76
76
  callback: lambda { |data|
77
77
  return 4 if data.length > 3
@@ -80,8 +80,8 @@ describe UvRays::AbstractTokenizer do
80
80
  })
81
81
 
82
82
  result = @buffer.extract('1234567starta')
83
- result.should == []
83
+ expect(result).to eq([])
84
84
  result = @buffer.extract('bcd')
85
- result.should == ['abcd']
85
+ expect(result).to eq(['abcd'])
86
86
  end
87
87
  end