uv-rays 1.0.4 → 1.0.5
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/LICENSE +0 -0
- data/README.md +0 -0
- data/Rakefile +0 -0
- data/lib/uv-rays.rb +0 -0
- data/lib/uv-rays/abstract_tokenizer.rb +0 -0
- data/lib/uv-rays/buffered_tokenizer.rb +72 -30
- data/lib/uv-rays/connection.rb +0 -0
- data/lib/uv-rays/http/encoding.rb +0 -0
- data/lib/uv-rays/http/request.rb +0 -0
- data/lib/uv-rays/http/response.rb +0 -0
- data/lib/uv-rays/http_endpoint.rb +0 -0
- data/lib/uv-rays/scheduler/cron.rb +0 -0
- data/lib/uv-rays/scheduler/time.rb +1 -1
- data/lib/uv-rays/tcp_server.rb +0 -0
- data/lib/uv-rays/version.rb +1 -1
- data/spec/abstract_tokenizer_spec.rb +0 -0
- data/spec/buffered_tokenizer_spec.rb +71 -0
- data/spec/connection_spec.rb +0 -0
- data/spec/http_endpoint_spec.rb +0 -0
- data/spec/scheduler_cron_spec.rb +0 -0
- data/spec/scheduler_spec.rb +0 -0
- data/spec/scheduler_time_spec.rb +0 -0
- data/uv-rays.gemspec +0 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 144879cc69e227ca059cecbd2b4abf92d6fd0284
|
4
|
+
data.tar.gz: e57957308a1ba65488d48e8c451794161af23476
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 518a38b3f152899f36af5cd9488ffd1cd6ec7f983ca01cb8e909e8f831de9a7ee049fe8dbffe6e9b6bf2d2366e34907fb2ff5dd3f945b55de63a5ec6319510c7
|
7
|
+
data.tar.gz: 21751e286a6a2aa6e9dbd873c1712611dff769a52778fadaeb6d1b88600682c6be8d243f6995c64ae960578356cdc20b9a36e3b432704cf6bff59a0f8d2a4bae
|
data/LICENSE
CHANGED
File without changes
|
data/README.md
CHANGED
File without changes
|
data/Rakefile
CHANGED
File without changes
|
data/lib/uv-rays.rb
CHANGED
File without changes
|
File without changes
|
@@ -22,19 +22,22 @@ module UV
|
|
22
22
|
def initialize(options)
|
23
23
|
@delimiter = options[:delimiter]
|
24
24
|
@indicator = options[:indicator]
|
25
|
+
@msg_length = options[:msg_length]
|
25
26
|
@size_limit = options[:size_limit]
|
26
27
|
@min_length = options[:min_length] || 1
|
27
28
|
@verbose = options[:verbose] if @size_limit
|
28
29
|
@encoding = options[:encoding]
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
@
|
33
|
-
|
34
|
-
@
|
35
|
-
|
36
|
-
|
31
|
+
if @delimiter
|
32
|
+
@extract_method = method(:delimiter_extract)
|
33
|
+
elsif @indicator && @msg_length
|
34
|
+
@length_index = @msg_length - 1
|
35
|
+
@extract_method = method(:length_extract)
|
36
|
+
else
|
37
|
+
raise ArgumentError, 'no delimiter provided'
|
37
38
|
end
|
39
|
+
|
40
|
+
init_buffer
|
38
41
|
end
|
39
42
|
|
40
43
|
# Extract takes an arbitrary string of input data and returns an array of
|
@@ -50,6 +53,29 @@ module UV
|
|
50
53
|
data.force_encoding(@encoding) if @encoding
|
51
54
|
@input << data
|
52
55
|
|
56
|
+
@extract_method.call
|
57
|
+
end
|
58
|
+
|
59
|
+
# Flush the contents of the input buffer, i.e. return the input buffer even though
|
60
|
+
# a token has not yet been encountered.
|
61
|
+
#
|
62
|
+
# @return [String]
|
63
|
+
def flush
|
64
|
+
buffer = @input
|
65
|
+
reset
|
66
|
+
buffer
|
67
|
+
end
|
68
|
+
|
69
|
+
# @return [Boolean]
|
70
|
+
def empty?
|
71
|
+
@input.empty?
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
|
78
|
+
def delimiter_extract
|
53
79
|
# Extract token-delimited entities from the input string with the split command.
|
54
80
|
# There's a bit of craftiness here with the -1 parameter. Normally split would
|
55
81
|
# behave no differently regardless of if the token lies at the very end of the
|
@@ -70,7 +96,38 @@ module UV
|
|
70
96
|
@input = entities.pop
|
71
97
|
end
|
72
98
|
|
73
|
-
|
99
|
+
check_buffer_limits
|
100
|
+
|
101
|
+
# Check min-length is met
|
102
|
+
entities.select! {|msg| msg.length >= @min_length}
|
103
|
+
|
104
|
+
return entities
|
105
|
+
end
|
106
|
+
|
107
|
+
def length_extract
|
108
|
+
messages = @input.split(@indicator, -1)
|
109
|
+
messages.shift # discard junk data
|
110
|
+
|
111
|
+
last = messages.pop || ''
|
112
|
+
|
113
|
+
# Select messages of the right size then remove junk data
|
114
|
+
messages.select! { |msg| msg.length >= @msg_length ? true : false }
|
115
|
+
messages.map! { |msg| msg[0..@length_index] }
|
116
|
+
|
117
|
+
if last.length >= @msg_length
|
118
|
+
messages << last[0..@length_index]
|
119
|
+
@input = last[@msg_length..-1]
|
120
|
+
else
|
121
|
+
@input = "#{@indicator}#{last}"
|
122
|
+
end
|
123
|
+
|
124
|
+
check_buffer_limits
|
125
|
+
|
126
|
+
return messages
|
127
|
+
end
|
128
|
+
|
129
|
+
# Check to see if the buffer has exceeded capacity, if we're imposing a limit
|
130
|
+
def check_buffer_limits
|
74
131
|
if @size_limit && @input.size > @size_limit
|
75
132
|
if @indicator && @indicator.respond_to?(:length) # check for regex
|
76
133
|
# save enough of the buffer that if one character of the indicator were
|
@@ -83,32 +140,17 @@ module UV
|
|
83
140
|
end
|
84
141
|
raise 'input buffer exceeded limit' if @verbose
|
85
142
|
end
|
86
|
-
|
87
|
-
# Check min-length is met
|
88
|
-
entities.select! {|msg| msg.length >= @min_length}
|
89
|
-
|
90
|
-
return entities
|
91
|
-
end
|
92
|
-
|
93
|
-
# Flush the contents of the input buffer, i.e. return the input buffer even though
|
94
|
-
# a token has not yet been encountered.
|
95
|
-
#
|
96
|
-
# @return [String]
|
97
|
-
def flush
|
98
|
-
buffer = @input
|
99
|
-
reset
|
100
|
-
buffer
|
101
143
|
end
|
102
144
|
|
103
|
-
|
104
|
-
|
105
|
-
@
|
145
|
+
def init_buffer
|
146
|
+
@input = ''
|
147
|
+
if @encoding
|
148
|
+
@input.force_encoding(@encoding)
|
149
|
+
@delimiter.force_encoding(@encoding) if @delimiter.is_a?(String)
|
150
|
+
@indicator.force_encoding(@encoding) if @indicator.is_a?(String)
|
151
|
+
end
|
106
152
|
end
|
107
153
|
|
108
|
-
|
109
|
-
private
|
110
|
-
|
111
|
-
|
112
154
|
def reset
|
113
155
|
@input = ''
|
114
156
|
@input.force_encoding(@encoding) if @encoding
|
data/lib/uv-rays/connection.rb
CHANGED
File without changes
|
File without changes
|
data/lib/uv-rays/http/request.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/uv-rays/tcp_server.rb
CHANGED
File without changes
|
data/lib/uv-rays/version.rb
CHANGED
File without changes
|
@@ -173,6 +173,77 @@ describe UV::BufferedTokenizer do
|
|
173
173
|
end
|
174
174
|
end
|
175
175
|
|
176
|
+
describe 'indicator with length' do
|
177
|
+
before :each do
|
178
|
+
@buffer = UV::BufferedTokenizer.new({
|
179
|
+
indicator: "GO",
|
180
|
+
msg_length: 4 # length without the indicator
|
181
|
+
})
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should not return anything when a complete message is not available" do
|
185
|
+
msg1 = "GO123"
|
186
|
+
|
187
|
+
result = @buffer.extract(msg1)
|
188
|
+
expect(result).to eq([])
|
189
|
+
end
|
190
|
+
|
191
|
+
it "should not return anything when the messages is empty" do
|
192
|
+
msg1 = ""
|
193
|
+
|
194
|
+
result = @buffer.extract(msg1)
|
195
|
+
expect(result).to eq([])
|
196
|
+
end
|
197
|
+
|
198
|
+
it "should tokenize messages where the data is a complete message" do
|
199
|
+
msg1 = "GO1234"
|
200
|
+
|
201
|
+
result = @buffer.extract(msg1)
|
202
|
+
expect(result).to eq(['1234'])
|
203
|
+
end
|
204
|
+
|
205
|
+
it "should discard data that is not relevant" do
|
206
|
+
msg1 = "1234-GO1234"
|
207
|
+
|
208
|
+
result = @buffer.extract(msg1)
|
209
|
+
expect(result).to eq(['1234'])
|
210
|
+
end
|
211
|
+
|
212
|
+
it "should return multiple complete messages" do
|
213
|
+
msg1 = "GO1234GOhome"
|
214
|
+
|
215
|
+
result = @buffer.extract(msg1)
|
216
|
+
expect(result).to eq(['1234', 'home'])
|
217
|
+
end
|
218
|
+
|
219
|
+
it "should discard data between multiple complete messages" do
|
220
|
+
msg1 = "1234-GO123412345-GOhome"
|
221
|
+
|
222
|
+
result = @buffer.extract(msg1)
|
223
|
+
expect(result).to eq(['1234', 'home'])
|
224
|
+
end
|
225
|
+
|
226
|
+
it "should tokenize messages where the indicator is split" do
|
227
|
+
msg1 = "GOtestG"
|
228
|
+
msg2 = "Owhoa"
|
229
|
+
|
230
|
+
result = @buffer.extract(msg1)
|
231
|
+
expect(result).to eq(['test'])
|
232
|
+
result = @buffer.extract(msg2)
|
233
|
+
expect(result).to eq(['whoa'])
|
234
|
+
end
|
235
|
+
|
236
|
+
it "should tokenize messages where the indicator is split and there is discard data" do
|
237
|
+
msg1 = "GOtest\n\r1234G"
|
238
|
+
msg2 = "Owhoa\n"
|
239
|
+
|
240
|
+
result = @buffer.extract(msg1)
|
241
|
+
expect(result).to eq(['test'])
|
242
|
+
result = @buffer.extract(msg2)
|
243
|
+
expect(result).to eq(['whoa'])
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
176
247
|
describe 'buffer size limit with indicator' do
|
177
248
|
before :each do
|
178
249
|
@buffer = UV::BufferedTokenizer.new({
|
data/spec/connection_spec.rb
CHANGED
File without changes
|
data/spec/http_endpoint_spec.rb
CHANGED
File without changes
|
data/spec/scheduler_cron_spec.rb
CHANGED
File without changes
|
data/spec/scheduler_spec.rb
CHANGED
File without changes
|
data/spec/scheduler_time_spec.rb
CHANGED
File without changes
|
data/uv-rays.gemspec
CHANGED
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uv-rays
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen von Takach
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: libuv
|
@@ -202,7 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
202
202
|
version: '0'
|
203
203
|
requirements: []
|
204
204
|
rubyforge_project:
|
205
|
-
rubygems_version: 2.
|
205
|
+
rubygems_version: 2.4.5
|
206
206
|
signing_key:
|
207
207
|
specification_version: 4
|
208
208
|
summary: Abstractions for working with Libuv
|