restruct 0.1.0 → 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 +4 -4
- data/.travis.yml +4 -1
- data/Gemfile +0 -2
- data/README.md +8 -5
- data/Rakefile +6 -0
- data/lib/restruct.rb +2 -0
- data/lib/restruct/channel.rb +31 -0
- data/lib/restruct/connection.rb +9 -0
- data/lib/restruct/id.rb +4 -0
- data/lib/restruct/marshal_channel.rb +5 -0
- data/lib/restruct/version.rb +1 -1
- data/restruct.gemspec +14 -6
- data/spec/channel_spec.rb +33 -0
- data/spec/connection_spec.rb +1 -0
- data/spec/coverage_helper.rb +1 -4
- data/spec/hash_spec.rb +64 -64
- data/spec/id_spec.rb +1 -2
- data/spec/minitest_helper.rb +3 -7
- data/spec/nested_hash_spec.rb +65 -65
- metadata +54 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b08da180cd16bfdb19e965f58ed2f6bdc0590558
|
4
|
+
data.tar.gz: 5eb60adcfa2585711ae48a8b26718d062c0fad8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15795162d1328da9f16764494398379e87004db5e9491672d60ebe94d99d17ba5ac8f7eaf83648f3a62b31aa34caa2c70350abbb730790131bb1ff54e1832b0e
|
7
|
+
data.tar.gz: 1bf098b79cdc7b020abf55849fe5a9fe399e0c6a43c9e0bc9efd65523df97ecf3d923610e756925632e8cf6a416588faf1d816669fbce95f8977592bcf7256a1
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# Restruct
|
2
2
|
|
3
|
-
[](https://rubygems.org/gems/restruct)
|
4
|
+
[](https://travis-ci.org/gabynaiman/restruct)
|
5
|
+
[](https://coveralls.io/r/gabynaiman/restruct?branch=master)
|
6
|
+
[](https://codeclimate.com/github/gabynaiman/restruct)
|
7
|
+
[](https://gemnasium.com/gabynaiman/restruct)
|
8
8
|
|
9
9
|
Redis structures
|
10
10
|
|
@@ -12,6 +12,9 @@ Redis structures
|
|
12
12
|
- Set
|
13
13
|
- Hash
|
14
14
|
- NestedHash
|
15
|
+
- Queue
|
16
|
+
- Locker
|
17
|
+
- Channel
|
15
18
|
|
16
19
|
## Installation
|
17
20
|
|
data/Rakefile
CHANGED
@@ -5,6 +5,12 @@ Rake::TestTask.new(:spec) do |t|
|
|
5
5
|
t.libs << 'spec'
|
6
6
|
t.pattern = 'spec/**/*_spec.rb'
|
7
7
|
t.verbose = false
|
8
|
+
t.warning = false
|
9
|
+
t.loader = nil if ENV['TEST']
|
10
|
+
ENV['TEST'], ENV['LINE'] = ENV['TEST'].split(':') if ENV['TEST'] && !ENV['LINE']
|
11
|
+
t.options = ''
|
12
|
+
t.options << "--name=/#{ENV['NAME']}/ " if ENV['NAME']
|
13
|
+
t.options << "-l #{ENV['LINE']} " if ENV['LINE'] && ENV['TEST']
|
8
14
|
end
|
9
15
|
|
10
16
|
task :console do
|
data/lib/restruct.rb
CHANGED
@@ -11,12 +11,14 @@ require_relative 'restruct/array'
|
|
11
11
|
require_relative 'restruct/set'
|
12
12
|
require_relative 'restruct/hash'
|
13
13
|
require_relative 'restruct/queue'
|
14
|
+
require_relative 'restruct/channel'
|
14
15
|
require_relative 'restruct/nested_hash'
|
15
16
|
require_relative 'restruct/marshalizable'
|
16
17
|
require_relative 'restruct/marshal_array'
|
17
18
|
require_relative 'restruct/marshal_set'
|
18
19
|
require_relative 'restruct/marshal_hash'
|
19
20
|
require_relative 'restruct/marshal_queue'
|
21
|
+
require_relative 'restruct/marshal_channel'
|
20
22
|
require_relative 'restruct/locker'
|
21
23
|
require_relative 'restruct/connection'
|
22
24
|
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Restruct
|
2
|
+
class Channel < Structure
|
3
|
+
|
4
|
+
def publish(message)
|
5
|
+
connection.call 'PUBLISH', id, serialize(message)
|
6
|
+
end
|
7
|
+
|
8
|
+
def subscribe
|
9
|
+
subscriber = connection.clone
|
10
|
+
subscriber.call 'SUBSCRIBE', id
|
11
|
+
loop do
|
12
|
+
yield deserialize(subscriber.read.last)
|
13
|
+
end
|
14
|
+
rescue => ex
|
15
|
+
raise ex
|
16
|
+
ensure
|
17
|
+
subscriber.call 'UNSUBSCRIBE', id
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def serialize(string)
|
23
|
+
string
|
24
|
+
end
|
25
|
+
|
26
|
+
def deserialize(string)
|
27
|
+
string
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
data/lib/restruct/connection.rb
CHANGED
@@ -2,6 +2,7 @@ module Restruct
|
|
2
2
|
class Connection
|
3
3
|
|
4
4
|
def initialize(*args)
|
5
|
+
@args = args
|
5
6
|
@redis = Redic.new *args
|
6
7
|
@scripts = {}
|
7
8
|
@nesting = ::Hash.new { |h,k| h[k] = 0 }
|
@@ -44,6 +45,14 @@ module Restruct
|
|
44
45
|
raise ex
|
45
46
|
end
|
46
47
|
|
48
|
+
def read
|
49
|
+
redis.client.read
|
50
|
+
end
|
51
|
+
|
52
|
+
def clone
|
53
|
+
Connection.new *@args
|
54
|
+
end
|
55
|
+
|
47
56
|
private
|
48
57
|
|
49
58
|
attr_reader :redis, :scripts
|
data/lib/restruct/id.rb
CHANGED
data/lib/restruct/version.rb
CHANGED
data/restruct.gemspec
CHANGED
@@ -21,11 +21,19 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_dependency 'redic', '~> 1.5.0'
|
22
22
|
spec.add_dependency 'class_config', '~> 0.0.1'
|
23
23
|
|
24
|
-
spec.add_development_dependency 'bundler', '~> 1.
|
25
|
-
spec.add_development_dependency 'rake'
|
26
|
-
spec.add_development_dependency 'minitest', '~>
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
25
|
+
spec.add_development_dependency 'rake', '~> 11.0'
|
26
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
27
27
|
spec.add_development_dependency "minitest-great_expectations"
|
28
|
-
spec.add_development_dependency '
|
29
|
-
spec.add_development_dependency '
|
30
|
-
spec.add_development_dependency '
|
28
|
+
spec.add_development_dependency 'minitest-colorin', '~> 0.1'
|
29
|
+
spec.add_development_dependency 'minitest-line', '~> 0.6'
|
30
|
+
spec.add_development_dependency 'simplecov', '~> 0.12'
|
31
|
+
spec.add_development_dependency 'coveralls', '~> 0.8'
|
32
|
+
spec.add_development_dependency 'pry-nav', '~> 0.2'
|
33
|
+
|
34
|
+
if RUBY_VERSION < '2'
|
35
|
+
spec.add_development_dependency 'term-ansicolor', '~> 1.3.0'
|
36
|
+
spec.add_development_dependency 'tins', '~> 1.6.0'
|
37
|
+
spec.add_development_dependency 'json', '~> 1.8'
|
38
|
+
end
|
31
39
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'minitest_helper'
|
2
|
+
|
3
|
+
[Restruct::Channel, Restruct::MarshalChannel].each do |klass|
|
4
|
+
|
5
|
+
describe klass do
|
6
|
+
|
7
|
+
let(:channel) { klass.new }
|
8
|
+
|
9
|
+
it 'Subscribe and publish' do
|
10
|
+
messages = []
|
11
|
+
|
12
|
+
Thread.new do
|
13
|
+
channel.subscribe do |message|
|
14
|
+
messages << message
|
15
|
+
end
|
16
|
+
end
|
17
|
+
sleep 0.01 # Wait for establish connection
|
18
|
+
|
19
|
+
3.times do |i|
|
20
|
+
channel.publish "Message #{i}"
|
21
|
+
end
|
22
|
+
|
23
|
+
Timeout.timeout(3) do
|
24
|
+
while messages.count < 3;
|
25
|
+
sleep 0.0001 # Wait for subscriptions
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
messages.must_equal 3.times.map { |i| "Message #{i}" }
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
data/spec/connection_spec.rb
CHANGED
data/spec/coverage_helper.rb
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
require 'simplecov'
|
2
2
|
require 'coveralls'
|
3
3
|
|
4
|
-
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
5
|
-
SimpleCov::Formatter::HTMLFormatter,
|
6
|
-
Coveralls::SimpleCov::Formatter
|
7
|
-
]
|
4
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new [SimpleCov::Formatter::HTMLFormatter, Coveralls::SimpleCov::Formatter]
|
8
5
|
SimpleCov.start
|
data/spec/hash_spec.rb
CHANGED
@@ -4,11 +4,11 @@ require 'minitest_helper'
|
|
4
4
|
|
5
5
|
describe klass do
|
6
6
|
|
7
|
-
let(:
|
7
|
+
let(:sample_hash) { klass.new }
|
8
8
|
|
9
9
|
def fill(data)
|
10
|
-
data.each { |k,v| data[k] =
|
11
|
-
connection.call 'HMSET',
|
10
|
+
data.each { |k,v| data[k] = sample_hash.send(:serialize, v) }
|
11
|
+
connection.call 'HMSET', sample_hash.id, *data.flatten
|
12
12
|
end
|
13
13
|
|
14
14
|
describe 'Getters' do
|
@@ -16,44 +16,44 @@ require 'minitest_helper'
|
|
16
16
|
it '[]' do
|
17
17
|
fill a: 'x', b: 'y'
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
sample_hash[:a].must_equal 'x'
|
20
|
+
sample_hash[:b].must_equal 'y'
|
21
|
+
sample_hash[:c].must_be_nil
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'fetch' do
|
25
25
|
fill a: 'x', b: 'y'
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
sample_hash.fetch(:a).must_equal 'x'
|
28
|
+
sample_hash.fetch(:b).must_equal 'y'
|
29
|
+
sample_hash.fetch(:c, 'z').must_equal 'z'
|
30
|
+
sample_hash.fetch(:c) { |k| k.to_s }.must_equal 'c'
|
31
31
|
|
32
|
-
error = proc {
|
32
|
+
error = proc { sample_hash.fetch(:c) }.must_raise KeyError
|
33
33
|
error.message.must_equal 'key not found: c'
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'key' do
|
37
37
|
fill a: 'x', b: 'y', c: 'y'
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
sample_hash.key('x').must_equal 'a'
|
40
|
+
sample_hash.key('y').must_equal 'b'
|
41
|
+
sample_hash.key('z').must_be_nil
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'keys' do
|
45
45
|
fill a: 'x', b: 'y', c: 'z'
|
46
|
-
|
46
|
+
sample_hash.keys.must_equal %w(a b c)
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'values' do
|
50
50
|
fill a: 'x', b: 'y', c: 'z'
|
51
|
-
|
51
|
+
sample_hash.values.must_equal %w(x y z)
|
52
52
|
end
|
53
53
|
|
54
54
|
it 'values_at' do
|
55
55
|
fill a: 'x', b: 'y', c: 'z'
|
56
|
-
|
56
|
+
sample_hash.values_at(:a, :f, :b, :g, :c).must_equal ['x', nil, 'y', nil, 'z']
|
57
57
|
end
|
58
58
|
|
59
59
|
end
|
@@ -64,11 +64,11 @@ require 'minitest_helper'
|
|
64
64
|
it method do
|
65
65
|
fill a: 'x', b: 'y'
|
66
66
|
|
67
|
-
|
68
|
-
|
67
|
+
sample_hash.send(method, :a, 'a').must_equal 'a'
|
68
|
+
sample_hash.to_h.must_equal 'a' => 'a', 'b' => 'y'
|
69
69
|
|
70
|
-
|
71
|
-
|
70
|
+
sample_hash.send(method, :c, 'z').must_equal 'z'
|
71
|
+
sample_hash.to_h.must_equal 'a' => 'a', 'b' => 'y', 'c' => 'z'
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
@@ -76,42 +76,42 @@ require 'minitest_helper'
|
|
76
76
|
it method do
|
77
77
|
fill a: 'x', b: 'y'
|
78
78
|
|
79
|
-
|
80
|
-
|
79
|
+
sample_hash.send(method, a: 'a', c: 'z').must_equal sample_hash
|
80
|
+
sample_hash.to_h.must_equal 'a' => 'a', 'b' => 'y', 'c' => 'z'
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
84
|
it 'delete' do
|
85
85
|
fill a: 'x', b: 'y'
|
86
86
|
|
87
|
-
|
88
|
-
|
87
|
+
sample_hash.delete(:b).must_equal 'y'
|
88
|
+
sample_hash.to_h.must_equal 'a' => 'x'
|
89
89
|
|
90
|
-
|
91
|
-
|
90
|
+
sample_hash.delete(:c).must_be_nil
|
91
|
+
sample_hash.to_h.must_equal 'a' => 'x'
|
92
92
|
end
|
93
93
|
|
94
94
|
it 'delete_if' do
|
95
95
|
fill a: 'x', b: 'y'
|
96
96
|
|
97
|
-
|
98
|
-
|
97
|
+
sample_hash.delete_if { |k,v| v == 'x' }.must_equal sample_hash
|
98
|
+
sample_hash.to_h.must_equal 'b' => 'y'
|
99
99
|
end
|
100
100
|
|
101
101
|
%w(keep_if select!).each do |method|
|
102
102
|
it method do
|
103
103
|
fill a: 'x', b: 'y'
|
104
104
|
|
105
|
-
|
106
|
-
|
105
|
+
sample_hash.send(method) { |k,v| v == 'x' }.must_equal sample_hash
|
106
|
+
sample_hash.to_h.must_equal 'a' => 'x'
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
110
110
|
it 'clear' do
|
111
111
|
fill a: 'x', b: 'y'
|
112
112
|
|
113
|
-
|
114
|
-
|
113
|
+
sample_hash.clear.must_equal sample_hash
|
114
|
+
sample_hash.must_be_empty
|
115
115
|
end
|
116
116
|
|
117
117
|
end
|
@@ -121,22 +121,22 @@ require 'minitest_helper'
|
|
121
121
|
%w(size count length).each do |method|
|
122
122
|
it method do
|
123
123
|
fill a: 'x', b: 'y'
|
124
|
-
|
124
|
+
sample_hash.send(method).must_equal 2
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
128
|
it 'empty?' do
|
129
|
-
|
129
|
+
sample_hash.must_be :empty?
|
130
130
|
fill a: 'x', b: 'y'
|
131
|
-
|
131
|
+
sample_hash.wont_be :empty?
|
132
132
|
end
|
133
133
|
|
134
134
|
%w(key? has_key?).each do |method|
|
135
135
|
it method do
|
136
136
|
fill a: 'x', b: 'y'
|
137
137
|
|
138
|
-
assert
|
139
|
-
refute
|
138
|
+
assert sample_hash.send(method, :a)
|
139
|
+
refute sample_hash.send(method, :c)
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
@@ -144,8 +144,8 @@ require 'minitest_helper'
|
|
144
144
|
it method do
|
145
145
|
fill a: 'x', b: 'y'
|
146
146
|
|
147
|
-
assert
|
148
|
-
refute
|
147
|
+
assert sample_hash.send(method, 'x')
|
148
|
+
refute sample_hash.send(method, 'z')
|
149
149
|
end
|
150
150
|
end
|
151
151
|
|
@@ -156,23 +156,23 @@ require 'minitest_helper'
|
|
156
156
|
%w(to_h to_primitive).each do |method|
|
157
157
|
it method do
|
158
158
|
fill a: 'x', b: 'y'
|
159
|
-
|
159
|
+
sample_hash.send(method).must_equal 'a' => 'x', 'b' => 'y'
|
160
160
|
end
|
161
161
|
end
|
162
162
|
|
163
163
|
it 'merge' do
|
164
164
|
fill a: 'x', b: 'y'
|
165
|
-
|
165
|
+
sample_hash.merge('c' => 'z', 'a' => 'a').must_equal 'a' => 'a', 'b' => 'y', 'c' => 'z'
|
166
166
|
end
|
167
167
|
|
168
168
|
it 'flatten' do
|
169
169
|
fill a: 'x', b: 'y'
|
170
|
-
|
170
|
+
sample_hash.flatten.must_equal %w(a x b y)
|
171
171
|
end
|
172
172
|
|
173
173
|
it 'invert' do
|
174
174
|
fill a: 'x', b: 'y'
|
175
|
-
|
175
|
+
sample_hash.invert.must_equal 'x' => 'a', 'y' => 'b'
|
176
176
|
end
|
177
177
|
|
178
178
|
end
|
@@ -189,13 +189,13 @@ require 'minitest_helper'
|
|
189
189
|
|
190
190
|
keys = []
|
191
191
|
values = []
|
192
|
-
|
192
|
+
sample_hash.send(method) do |k,v|
|
193
193
|
keys << k
|
194
194
|
values << v
|
195
195
|
end
|
196
196
|
|
197
|
-
keys.must_equal
|
198
|
-
values.must_equal
|
197
|
+
keys.must_equal sample_hash.keys
|
198
|
+
values.must_equal sample_hash.values
|
199
199
|
end
|
200
200
|
end
|
201
201
|
|
@@ -203,52 +203,52 @@ require 'minitest_helper'
|
|
203
203
|
fill a: 'x', b: 'y'
|
204
204
|
|
205
205
|
keys = []
|
206
|
-
|
206
|
+
sample_hash.each_key { |k| keys << k }
|
207
207
|
|
208
|
-
keys.must_equal
|
208
|
+
keys.must_equal sample_hash.keys
|
209
209
|
end
|
210
210
|
|
211
211
|
it 'each_value' do
|
212
212
|
fill a: 'x', b: 'y'
|
213
213
|
|
214
214
|
values = []
|
215
|
-
|
215
|
+
sample_hash.each_value { |v| values << v }
|
216
216
|
|
217
|
-
values.must_equal
|
217
|
+
values.must_equal sample_hash.values
|
218
218
|
end
|
219
219
|
|
220
220
|
end
|
221
221
|
|
222
222
|
it 'Equality' do
|
223
|
-
copy = klass.new id:
|
224
|
-
assert
|
225
|
-
assert
|
226
|
-
refute
|
223
|
+
copy = klass.new id: sample_hash.id
|
224
|
+
assert sample_hash == copy
|
225
|
+
assert sample_hash.eql? copy
|
226
|
+
refute sample_hash.equal? copy
|
227
227
|
end
|
228
228
|
|
229
229
|
it 'Dump/Restore' do
|
230
230
|
fill a: 'x', b: 'y'
|
231
231
|
|
232
|
-
dump =
|
232
|
+
dump = sample_hash.dump
|
233
233
|
other = klass.new
|
234
234
|
other.restore dump
|
235
235
|
|
236
|
-
other.id.wont_equal
|
237
|
-
other.to_primitive.must_equal
|
236
|
+
other.id.wont_equal sample_hash.id
|
237
|
+
other.to_primitive.must_equal sample_hash.to_primitive
|
238
238
|
end
|
239
239
|
|
240
240
|
it 'Batch' do
|
241
241
|
fill a: 'x', b: 'y', c: 'z'
|
242
242
|
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
243
|
+
sample_hash.connection.batch do
|
244
|
+
sample_hash[:d] = 'w'
|
245
|
+
sample_hash.delete :a
|
246
|
+
sample_hash.merge! b: 'x', e: 'v'
|
247
247
|
|
248
|
-
|
248
|
+
sample_hash.to_h.must_equal 'a' => 'x', 'b' => 'y', 'c' => 'z'
|
249
249
|
end
|
250
250
|
|
251
|
-
|
251
|
+
sample_hash.to_h.must_equal 'b' => 'x', 'c' => 'z', 'd' => 'w', 'e' => 'v'
|
252
252
|
end
|
253
253
|
|
254
254
|
end
|
data/spec/id_spec.rb
CHANGED
data/spec/minitest_helper.rb
CHANGED
@@ -1,17 +1,12 @@
|
|
1
1
|
require 'coverage_helper'
|
2
2
|
require 'restruct'
|
3
3
|
require 'minitest/autorun'
|
4
|
+
require 'minitest/colorin'
|
4
5
|
require 'minitest/great_expectations'
|
5
|
-
require 'turn'
|
6
6
|
require 'pry-nav'
|
7
7
|
|
8
|
-
Turn.config do |c|
|
9
|
-
c.format = :pretty
|
10
|
-
c.natural = true
|
11
|
-
c.ansi = true
|
12
|
-
end
|
13
|
-
|
14
8
|
class Minitest::Spec
|
9
|
+
|
15
10
|
def connection
|
16
11
|
Restruct.connection
|
17
12
|
end
|
@@ -19,4 +14,5 @@ class Minitest::Spec
|
|
19
14
|
after do
|
20
15
|
connection.call('KEYS', Restruct::Id.new(:restruct)['*']).each { |k| connection.call 'DEL', k }
|
21
16
|
end
|
17
|
+
|
22
18
|
end
|
data/spec/nested_hash_spec.rb
CHANGED
@@ -17,42 +17,42 @@ CounterHash = Restruct::NestedHash.new(Counter)
|
|
17
17
|
|
18
18
|
describe Restruct::NestedHash do
|
19
19
|
|
20
|
-
let(:
|
20
|
+
let(:counter_hash) { CounterHash.new }
|
21
21
|
|
22
22
|
describe 'Getters' do
|
23
23
|
|
24
24
|
it '[]' do
|
25
|
-
|
25
|
+
counter_hash[:a].current.must_equal 0
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'fetch' do
|
29
|
-
|
29
|
+
counter_hash[:a].incr
|
30
30
|
|
31
|
-
|
31
|
+
counter_hash.fetch(:a).current.must_equal 1
|
32
32
|
|
33
|
-
error = proc {
|
33
|
+
error = proc { counter_hash.fetch(:c) }.must_raise KeyError
|
34
34
|
error.message.must_equal 'key not found: c'
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'keys' do
|
38
|
-
|
39
|
-
|
38
|
+
counter_hash[:a].incr
|
39
|
+
counter_hash[:b].incr
|
40
40
|
|
41
|
-
|
41
|
+
counter_hash.keys.must_equal %w(a b)
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'values' do
|
45
|
-
|
46
|
-
|
45
|
+
counter_hash[:a].incr.incr
|
46
|
+
counter_hash[:b].incr
|
47
47
|
|
48
|
-
|
48
|
+
counter_hash.values.map(&:current).must_equal [2, 1]
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'values_at' do
|
52
|
-
|
53
|
-
|
52
|
+
counter_hash[:a].incr.incr
|
53
|
+
counter_hash[:b].incr
|
54
54
|
|
55
|
-
|
55
|
+
counter_hash.values_at(:a, :f, :b, :g).map(&:current).must_equal [2, 0, 1, 0]
|
56
56
|
end
|
57
57
|
|
58
58
|
end
|
@@ -60,38 +60,38 @@ describe Restruct::NestedHash do
|
|
60
60
|
describe 'Setters' do
|
61
61
|
|
62
62
|
it 'delete' do
|
63
|
-
|
64
|
-
|
63
|
+
counter_hash[:a].incr.incr
|
64
|
+
counter_hash[:b].incr
|
65
65
|
|
66
|
-
|
66
|
+
counter_hash.delete(:a)
|
67
67
|
|
68
|
-
|
68
|
+
counter_hash.keys.must_equal %w(b)
|
69
69
|
end
|
70
70
|
|
71
71
|
it 'delete_if' do
|
72
|
-
|
73
|
-
|
72
|
+
counter_hash[:a].incr.incr
|
73
|
+
counter_hash[:b].incr
|
74
74
|
|
75
|
-
|
76
|
-
|
75
|
+
counter_hash.delete_if { |k,v| v.current > 1 }.must_equal counter_hash
|
76
|
+
counter_hash.keys.must_equal %w(b)
|
77
77
|
end
|
78
78
|
|
79
79
|
%w(keep_if select!).each do |method|
|
80
80
|
it method do
|
81
|
-
|
82
|
-
|
81
|
+
counter_hash[:a].incr.incr
|
82
|
+
counter_hash[:b].incr
|
83
83
|
|
84
|
-
|
85
|
-
|
84
|
+
counter_hash.send(method) { |k,v| v.current > 1 }.must_equal counter_hash
|
85
|
+
counter_hash.keys.must_equal %w(a)
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
89
|
it 'clear' do
|
90
|
-
|
91
|
-
|
90
|
+
counter_hash[:a].incr.incr
|
91
|
+
counter_hash[:b].incr
|
92
92
|
|
93
|
-
|
94
|
-
|
93
|
+
counter_hash.clear.must_equal counter_hash
|
94
|
+
counter_hash.must_be_empty
|
95
95
|
end
|
96
96
|
|
97
97
|
end
|
@@ -100,26 +100,26 @@ describe Restruct::NestedHash do
|
|
100
100
|
|
101
101
|
%w(size count length).each do |method|
|
102
102
|
it method do
|
103
|
-
|
104
|
-
|
103
|
+
counter_hash[:a].incr.incr
|
104
|
+
counter_hash[:b].incr
|
105
105
|
|
106
|
-
|
106
|
+
counter_hash.send(method).must_equal 2
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
110
110
|
it 'empty?' do
|
111
|
-
|
112
|
-
|
113
|
-
|
111
|
+
counter_hash.must_be :empty?
|
112
|
+
counter_hash[:a].incr
|
113
|
+
counter_hash.wont_be :empty?
|
114
114
|
end
|
115
115
|
|
116
116
|
%w(key? has_key?).each do |method|
|
117
117
|
it method do
|
118
|
-
|
119
|
-
|
118
|
+
counter_hash[:a].incr.incr
|
119
|
+
counter_hash[:b].incr
|
120
120
|
|
121
|
-
assert
|
122
|
-
refute
|
121
|
+
assert counter_hash.send(method, :a)
|
122
|
+
refute counter_hash.send(method, :c)
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
@@ -129,10 +129,10 @@ describe Restruct::NestedHash do
|
|
129
129
|
|
130
130
|
%w(to_h to_primitive).each do |method|
|
131
131
|
it method do
|
132
|
-
|
133
|
-
|
132
|
+
counter_hash[:a].incr.incr
|
133
|
+
counter_hash[:b].incr
|
134
134
|
|
135
|
-
|
135
|
+
counter_hash.send(method).must_equal 'a' => 2, 'b' => 1
|
136
136
|
end
|
137
137
|
end
|
138
138
|
|
@@ -146,60 +146,60 @@ describe Restruct::NestedHash do
|
|
146
146
|
|
147
147
|
%w(each each_pair).each do |method|
|
148
148
|
it method do
|
149
|
-
|
150
|
-
|
149
|
+
counter_hash[:a].incr.incr
|
150
|
+
counter_hash[:b].incr
|
151
151
|
|
152
152
|
keys = []
|
153
153
|
values = []
|
154
|
-
|
154
|
+
counter_hash.send(method) do |k,v|
|
155
155
|
keys << k
|
156
156
|
values << v
|
157
157
|
end
|
158
158
|
|
159
|
-
keys.must_equal
|
160
|
-
values.must_equal
|
159
|
+
keys.must_equal counter_hash.keys
|
160
|
+
values.must_equal counter_hash.values
|
161
161
|
end
|
162
162
|
end
|
163
163
|
|
164
164
|
it 'each_key' do
|
165
|
-
|
166
|
-
|
165
|
+
counter_hash[:a].incr.incr
|
166
|
+
counter_hash[:b].incr
|
167
167
|
|
168
168
|
keys = []
|
169
|
-
|
169
|
+
counter_hash.each_key { |k| keys << k }
|
170
170
|
|
171
|
-
keys.must_equal
|
171
|
+
keys.must_equal counter_hash.keys
|
172
172
|
end
|
173
173
|
|
174
174
|
it 'each_value' do
|
175
|
-
|
176
|
-
|
175
|
+
counter_hash[:a].incr.incr
|
176
|
+
counter_hash[:b].incr
|
177
177
|
|
178
178
|
values = []
|
179
|
-
|
179
|
+
counter_hash.each_value { |v| values << v }
|
180
180
|
|
181
|
-
values.must_equal
|
181
|
+
values.must_equal counter_hash.values
|
182
182
|
end
|
183
183
|
|
184
184
|
end
|
185
185
|
|
186
186
|
it 'Equality' do
|
187
|
-
copy = CounterHash.new id:
|
188
|
-
assert
|
189
|
-
assert
|
190
|
-
refute
|
187
|
+
copy = CounterHash.new id: counter_hash.id
|
188
|
+
assert counter_hash == copy
|
189
|
+
assert counter_hash.eql? copy
|
190
|
+
refute counter_hash.equal? copy
|
191
191
|
end
|
192
192
|
|
193
193
|
it 'Dump/Restore' do
|
194
|
-
|
195
|
-
|
194
|
+
counter_hash[:a].incr.incr
|
195
|
+
counter_hash[:b].incr
|
196
196
|
|
197
|
-
dump =
|
197
|
+
dump = counter_hash.dump
|
198
198
|
other = CounterHash.new
|
199
199
|
other.restore dump
|
200
200
|
|
201
|
-
other.id.wont_equal
|
202
|
-
other.to_primitive.must_equal
|
201
|
+
other.id.wont_equal counter_hash.id
|
202
|
+
other.to_primitive.must_equal counter_hash.to_primitive
|
203
203
|
end
|
204
204
|
|
205
205
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restruct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriel Naiman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redic
|
@@ -44,42 +44,42 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '1.
|
47
|
+
version: '1.12'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '1.
|
54
|
+
version: '1.12'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
61
|
+
version: '11.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
68
|
+
version: '11.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: minitest
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ~>
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '5.0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - ~>
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '5.0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: minitest-great_expectations
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,47 +95,75 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: minitest-colorin
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.1'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.1'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: minitest-line
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
100
114
|
requirements:
|
101
115
|
- - ~>
|
102
116
|
- !ruby/object:Gem::Version
|
103
|
-
version: '0.
|
117
|
+
version: '0.6'
|
104
118
|
type: :development
|
105
119
|
prerelease: false
|
106
120
|
version_requirements: !ruby/object:Gem::Requirement
|
107
121
|
requirements:
|
108
122
|
- - ~>
|
109
123
|
- !ruby/object:Gem::Version
|
110
|
-
version: '0.
|
124
|
+
version: '0.6'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: simplecov
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
114
128
|
requirements:
|
115
|
-
- -
|
129
|
+
- - ~>
|
116
130
|
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
131
|
+
version: '0.12'
|
118
132
|
type: :development
|
119
133
|
prerelease: false
|
120
134
|
version_requirements: !ruby/object:Gem::Requirement
|
121
135
|
requirements:
|
122
|
-
- -
|
136
|
+
- - ~>
|
123
137
|
- !ruby/object:Gem::Version
|
124
|
-
version: '0'
|
138
|
+
version: '0.12'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: coveralls
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ~>
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0.8'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ~>
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0.8'
|
125
153
|
- !ruby/object:Gem::Dependency
|
126
154
|
name: pry-nav
|
127
155
|
requirement: !ruby/object:Gem::Requirement
|
128
156
|
requirements:
|
129
|
-
- -
|
157
|
+
- - ~>
|
130
158
|
- !ruby/object:Gem::Version
|
131
|
-
version: '0'
|
159
|
+
version: '0.2'
|
132
160
|
type: :development
|
133
161
|
prerelease: false
|
134
162
|
version_requirements: !ruby/object:Gem::Requirement
|
135
163
|
requirements:
|
136
|
-
- -
|
164
|
+
- - ~>
|
137
165
|
- !ruby/object:Gem::Version
|
138
|
-
version: '0'
|
166
|
+
version: '0.2'
|
139
167
|
description: Redis structures
|
140
168
|
email:
|
141
169
|
- gabynaiman@gmail.com
|
@@ -154,12 +182,14 @@ files:
|
|
154
182
|
- Rakefile
|
155
183
|
- lib/restruct.rb
|
156
184
|
- lib/restruct/array.rb
|
185
|
+
- lib/restruct/channel.rb
|
157
186
|
- lib/restruct/connection.rb
|
158
187
|
- lib/restruct/errors.rb
|
159
188
|
- lib/restruct/hash.rb
|
160
189
|
- lib/restruct/id.rb
|
161
190
|
- lib/restruct/locker.rb
|
162
191
|
- lib/restruct/marshal_array.rb
|
192
|
+
- lib/restruct/marshal_channel.rb
|
163
193
|
- lib/restruct/marshal_hash.rb
|
164
194
|
- lib/restruct/marshal_queue.rb
|
165
195
|
- lib/restruct/marshal_set.rb
|
@@ -173,6 +203,7 @@ files:
|
|
173
203
|
- lua/unregister.lua
|
174
204
|
- restruct.gemspec
|
175
205
|
- spec/array_spec.rb
|
206
|
+
- spec/channel_spec.rb
|
176
207
|
- spec/connection_spec.rb
|
177
208
|
- spec/coverage_helper.rb
|
178
209
|
- spec/hash_spec.rb
|
@@ -202,12 +233,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
202
233
|
version: '0'
|
203
234
|
requirements: []
|
204
235
|
rubyforge_project:
|
205
|
-
rubygems_version: 2.4.
|
236
|
+
rubygems_version: 2.4.8
|
206
237
|
signing_key:
|
207
238
|
specification_version: 4
|
208
239
|
summary: Redis structures
|
209
240
|
test_files:
|
210
241
|
- spec/array_spec.rb
|
242
|
+
- spec/channel_spec.rb
|
211
243
|
- spec/connection_spec.rb
|
212
244
|
- spec/coverage_helper.rb
|
213
245
|
- spec/hash_spec.rb
|