restruct 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,7 @@
1
1
  require 'coverage_helper'
2
2
  require 'restruct'
3
3
  require 'minitest/autorun'
4
+ require 'minitest/great_expectations'
4
5
  require 'turn'
5
6
  require 'pry-nav'
6
7
 
@@ -11,11 +12,11 @@ Turn.config do |c|
11
12
  end
12
13
 
13
14
  class Minitest::Spec
14
- def redis
15
- Restruct.redis
15
+ def connection
16
+ Restruct.connection
16
17
  end
17
18
 
18
19
  after do
19
- redis.call('KEYS', Restruct::Id.new(:restruct)['*']).each { |k| redis.call 'DEL', k }
20
+ connection.call('KEYS', Restruct::Id.new(:restruct)['*']).each { |k| connection.call 'DEL', k }
20
21
  end
21
22
  end
@@ -2,12 +2,12 @@ require 'minitest_helper'
2
2
 
3
3
  class Counter < Restruct::Structure
4
4
  def current
5
- (redis.call('GET', id) || 0).to_i
5
+ (connection.call('GET', id) || 0).to_i
6
6
  end
7
7
  alias_method :to_primitive, :current
8
8
 
9
9
  def incr
10
- redis.call 'SET', id, current + 1
10
+ connection.call 'SET', id, current + 1
11
11
  self
12
12
  end
13
13
  end
@@ -0,0 +1,41 @@
1
+ require 'minitest_helper'
2
+
3
+ [Restruct::Queue, Restruct::MarshalQueue].each do |klass|
4
+
5
+ describe klass do
6
+
7
+ let(:queue) { klass.new }
8
+
9
+ it 'Push and pop' do
10
+ queue.must_be :empty?
11
+
12
+ queue.push 'test_1'
13
+ queue.push 'test_2'
14
+
15
+ queue.wont_be :empty?
16
+ queue.size.must_equal 2
17
+ queue.to_a.must_equal ['test_1', 'test_2']
18
+
19
+ queue.pop.must_equal 'test_1'
20
+ queue.wont_be :empty?
21
+ queue.size.must_equal 1
22
+ queue.to_a.must_equal ['test_2']
23
+
24
+ queue.pop.must_equal 'test_2'
25
+ queue.must_be :empty?
26
+ end
27
+
28
+ it 'Batch' do
29
+ %w(a b c).each {|e| queue.push e}
30
+
31
+ queue.connection.batch do
32
+ queue.push 'd'
33
+ queue.pop
34
+ queue.to_a.must_equal %w(a b c)
35
+ end
36
+
37
+ queue.to_a.must_equal %w(b c d)
38
+ end
39
+
40
+ end
41
+ end
@@ -7,7 +7,7 @@ require 'minitest_helper'
7
7
  let(:set) { klass.new }
8
8
 
9
9
  def fill(elements)
10
- redis.call 'SADD', set.id, *(elements.map { |e| set.send(:serialize, e) })
10
+ connection.call 'SADD', set.id, *(elements.map { |e| set.send(:serialize, e) })
11
11
  end
12
12
 
13
13
  describe 'Setters' do
@@ -252,6 +252,23 @@ require 'minitest_helper'
252
252
  other.to_primitive.must_equal set.to_primitive
253
253
  end
254
254
 
255
+ it 'Batch' do
256
+ fill %w(a b c)
257
+
258
+ set.connection.batch do
259
+ set.add 'd' #a b c d
260
+ set.add? 'x' #a b c d x
261
+ set.delete 'b' #a c d x
262
+ set.subtract %w(c d) #a x
263
+ set.merge %w(x y z) #a x y z
264
+ set.delete? 'a' #x y z
265
+
266
+ set.to_a.must_equal_contents %w(a b c)
267
+ end
268
+
269
+ set.to_a.must_equal_contents %w(x y z)
270
+ end
271
+
255
272
  end
256
273
 
257
274
  end
metadata CHANGED
@@ -1,125 +1,139 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restruct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.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: 2015-01-27 00:00:00.000000000 Z
11
+ date: 2015-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redic
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: 1.2.0
19
+ version: 1.5.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: 1.2.0
26
+ version: 1.5.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: class_config
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.0.1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.0.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: '1.6'
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
54
  version: '1.6'
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
61
  version: '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
68
  version: '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
75
  version: '4.7'
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
82
  version: '4.7'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest-great_expectations
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: turn
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
- - - "~>"
101
+ - - ~>
88
102
  - !ruby/object:Gem::Version
89
103
  version: '0.9'
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
- - - "~>"
108
+ - - ~>
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0.9'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: simplecov
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
- - - ">="
115
+ - - '>='
102
116
  - !ruby/object:Gem::Version
103
117
  version: '0'
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
124
  version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: pry-nav
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
- - - ">="
129
+ - - '>='
116
130
  - !ruby/object:Gem::Version
117
131
  version: '0'
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
138
  version: '0'
125
139
  description: Redis structures
@@ -129,36 +143,44 @@ executables: []
129
143
  extensions: []
130
144
  extra_rdoc_files: []
131
145
  files:
132
- - ".coveralls.yml"
133
- - ".gitignore"
134
- - ".ruby-gemset"
135
- - ".ruby-version"
136
- - ".travis.yml"
146
+ - .coveralls.yml
147
+ - .gitignore
148
+ - .ruby-gemset
149
+ - .ruby-version
150
+ - .travis.yml
137
151
  - Gemfile
138
152
  - LICENSE.txt
139
153
  - README.md
140
154
  - Rakefile
141
155
  - lib/restruct.rb
142
156
  - lib/restruct/array.rb
143
- - lib/restruct/batch.rb
157
+ - lib/restruct/connection.rb
158
+ - lib/restruct/errors.rb
144
159
  - lib/restruct/hash.rb
145
160
  - lib/restruct/id.rb
161
+ - lib/restruct/locker.rb
146
162
  - lib/restruct/marshal_array.rb
147
163
  - lib/restruct/marshal_hash.rb
164
+ - lib/restruct/marshal_queue.rb
148
165
  - lib/restruct/marshal_set.rb
149
166
  - lib/restruct/marshalizable.rb
150
167
  - lib/restruct/nested_hash.rb
168
+ - lib/restruct/queue.rb
151
169
  - lib/restruct/set.rb
152
170
  - lib/restruct/structure.rb
153
171
  - lib/restruct/version.rb
172
+ - lua/register.lua
173
+ - lua/unregister.lua
154
174
  - restruct.gemspec
155
175
  - spec/array_spec.rb
156
- - spec/batch_spec.rb
176
+ - spec/connection_spec.rb
157
177
  - spec/coverage_helper.rb
158
178
  - spec/hash_spec.rb
159
179
  - spec/id_spec.rb
180
+ - spec/locker_spec.rb
160
181
  - spec/minitest_helper.rb
161
182
  - spec/nested_hash_spec.rb
183
+ - spec/queue_spec.rb
162
184
  - spec/set_spec.rb
163
185
  homepage: https://github.com/gabynaiman/restruct
164
186
  licenses:
@@ -170,26 +192,28 @@ require_paths:
170
192
  - lib
171
193
  required_ruby_version: !ruby/object:Gem::Requirement
172
194
  requirements:
173
- - - ">="
195
+ - - '>='
174
196
  - !ruby/object:Gem::Version
175
197
  version: '0'
176
198
  required_rubygems_version: !ruby/object:Gem::Requirement
177
199
  requirements:
178
- - - ">="
200
+ - - '>='
179
201
  - !ruby/object:Gem::Version
180
202
  version: '0'
181
203
  requirements: []
182
204
  rubyforge_project:
183
- rubygems_version: 2.2.2
205
+ rubygems_version: 2.4.7
184
206
  signing_key:
185
207
  specification_version: 4
186
208
  summary: Redis structures
187
209
  test_files:
188
210
  - spec/array_spec.rb
189
- - spec/batch_spec.rb
211
+ - spec/connection_spec.rb
190
212
  - spec/coverage_helper.rb
191
213
  - spec/hash_spec.rb
192
214
  - spec/id_spec.rb
215
+ - spec/locker_spec.rb
193
216
  - spec/minitest_helper.rb
194
217
  - spec/nested_hash_spec.rb
218
+ - spec/queue_spec.rb
195
219
  - spec/set_spec.rb
@@ -1,39 +0,0 @@
1
- module Restruct
2
- class Batch
3
- class << self
4
-
5
- def execute(redis=nil)
6
- redis ||= Restruct.redis
7
- multi redis
8
- result = yield
9
- exec redis
10
- result
11
- rescue => ex
12
- discard redis
13
- raise ex
14
- end
15
-
16
- private
17
-
18
- def nesting
19
- @nesting ||= ::Hash.new { |h,k| h[k] = 0 }
20
- end
21
-
22
- def multi(redis)
23
- redis.call 'MULTI' if nesting[redis] == 0
24
- nesting[redis] += 1
25
- end
26
-
27
- def exec(redis)
28
- nesting[redis] -= 1
29
- redis.call 'EXEC' if nesting[redis] == 0
30
- end
31
-
32
- def discard(redis)
33
- nesting[redis] -= 1
34
- redis.call 'DISCARD' if nesting[redis] == 0
35
- end
36
-
37
- end
38
- end
39
- end
@@ -1,53 +0,0 @@
1
- require 'minitest_helper'
2
-
3
- describe Restruct::Batch do
4
-
5
- let(:connection) { Redic.new }
6
-
7
- it 'Execute' do
8
- hash = Restruct::Hash.new redis: connection
9
-
10
- Restruct::Batch.execute do
11
- h = Restruct::Hash.new id: hash.id
12
- h.merge! a: 'x', b: 'y', c: 'z'
13
-
14
- hash.must_be_empty
15
- end
16
-
17
- hash.to_h.must_equal 'a' => 'x', 'b' => 'y', 'c' => 'z'
18
- end
19
-
20
- it 'Discard' do
21
- hash = Restruct::Hash.new redis: connection
22
-
23
- proc do
24
- Restruct::Batch.execute do
25
- h = Restruct::Hash.new id: hash.id
26
- h.merge! a: 'x', b: 'y', c: 'z'
27
-
28
- raise 'Test error'
29
- end
30
- end.must_raise RuntimeError
31
-
32
- hash.must_be_empty
33
- end
34
-
35
- it 'Nested' do
36
- hash = Restruct::Hash.new redis: connection
37
-
38
- Restruct::Batch.execute do
39
- h = Restruct::Hash.new id: hash.id
40
- h.merge! a: 'x', b: 'y'
41
-
42
- Restruct::Batch.execute do
43
- h[:c] = 'z'
44
- hash.must_be_empty
45
- end
46
-
47
- hash.must_be_empty
48
- end
49
-
50
- hash.to_h.must_equal 'a' => 'x', 'b' => 'y', 'c' => 'z'
51
- end
52
-
53
- end