redis_object 1.3.0 → 1.3.1b

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MWYwNDNkM2UyZWQxZTI0ZjA5MzhlNDlhNjhmMWQxNTY4NGJiYzhmNQ==
4
+ YTk4ZjkxYzdmYzFjNTk0MTkzZjk1MWVjMDk4M2MzZjY0Nzg4NzRmNw==
5
5
  data.tar.gz: !binary |-
6
- ZDQ1ZGQ4MTVkYjI2NmExYWY5Yzk0ZGE4ZTQ0M2RkNzMxZGRjYTNkOA==
6
+ YTE4M2E2YjFhOGU4MDY0MDQ5N2UyNzgzYjNkZTViMWNkNWUwOTczMA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ODY4MGU5YmQwMDhjMTRjNzEzNmE0NjBhMjhlZDQwMTcyNDc1YTdiZDk0YzJh
10
- ZDEyOGJiMGE3NWQwNmU5ZTZmYzU0NGU3ZmUxNTdhYjAzNzM1MjkyN2ZjODRi
11
- MmMzM2VhMWY1NTQ5ODBkNzFmNTc2NDZmZjMxYTA0YmVhNGU4MGQ=
9
+ NmI4N2EwODRhMWYyMmFiNGY3NmIxMmFkNjcyOWY3YWYyYmNkYTc1NzViZTE5
10
+ ZGIxYjI3MjkxOTkzMDRiMTViMTIxNGE2MzJiYzBkZGNlZmJiZTUzNjZmYzVk
11
+ ZGU2MjRiODk0YTM2ZmExYjI2ODVhMzgwMzk1OTFjN2NmMmZkMzU=
12
12
  data.tar.gz: !binary |-
13
- OTU5OTE4ODYyMDU1ZDE5Zjg0NGYxOGI1ZmE0NjUwMjU2ZDk3MWZkYjAxOGI3
14
- Y2M3ZWEwZDcwODc2ODExMDY1MjQxMWQxOGQxZjZmNTZkZmE1ZTU2NDlhNDc3
15
- MjI2MmQ1ZTQxZjFlOGZkOWZiOGZiNzY0NDUxOWU4NWUxODcwNmM=
13
+ MDAxM2I2MmViMWFiMTA0ZmY2M2U1ZDRhMmQ5NTc2NGFiMGMzODdiNTJjNmU0
14
+ NTI0YTZlMjQ5ZWM3MmM0MGU2YTMyOTg3NmIzODg2Y2U4ZjgzMGMyMTUwZmY0
15
+ NzU4ZjQ0MDdhNGZiMDFhZTUxYjc0Y2E3NDNhZjgxNDI3ZGUyMGM=
data/lib/redis_object.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'active_support/inflector'
2
2
  require 'active_support/core_ext/date_time/conversions'
3
3
  require 'yajl'
4
+ require 'set'
4
5
 
5
6
  require "redis_object/storage"
6
7
 
@@ -93,7 +93,7 @@ module Seabright
93
93
  end
94
94
 
95
95
  def mset(dat)
96
- store.hmset(hkey, *(dat.inject([]){|acc,(k,v)| acc + [k,v] }))
96
+ store.hmset(hkey, *(dat.inject([]){|acc,(k,v)| acc << [k,v] }.flatten))
97
97
  cached_hash_values.merge!(dat)
98
98
  dat.each do |k,v|
99
99
  define_setter_getter(k)
@@ -185,8 +185,8 @@ module Seabright
185
185
  end
186
186
  end
187
187
 
188
- def id_sym(cls=self.class.cname)
189
- "#{cls.split('::').last.downcase}_id".to_sym
188
+ def id_sym(cls=nil)
189
+ self.class.id_sym(cls)
190
190
  end
191
191
 
192
192
  # Not used yet...
@@ -236,7 +236,7 @@ module Seabright
236
236
  end
237
237
 
238
238
  def cname
239
- self.name
239
+ name
240
240
  end
241
241
 
242
242
  def plname
@@ -244,8 +244,9 @@ module Seabright
244
244
  end
245
245
 
246
246
  def all
247
+ kys = store.smembers(plname)
247
248
  Enumerator.new do |y|
248
- store.smembers(plname).each do |member|
249
+ kys.each do |member|
249
250
  if a = find_by_key(hkey(member))
250
251
  y << a
251
252
  else
@@ -341,8 +342,9 @@ module Seabright
341
342
  return out".gsub(/\t/,'').freeze
342
343
 
343
344
  def match(pkt)
345
+ kys = run_script(pkt.keys.count > 1 ? :MultiMatcher : :Matcher,[plname],pkt.flatten.map{|i| i.is_a?(Regexp) ? convert_regex_to_lua(i) : i.to_s })
344
346
  Enumerator.new do |y|
345
- run_script(pkt.keys.count > 1 ? :MultiMatcher : :Matcher,[plname],pkt.flatten.map{|i| i.is_a?(Regexp) ? convert_regex_to_lua(i) : i.to_s }).each do |k|
347
+ kys.each do |k|
346
348
  y << find(k)
347
349
  end
348
350
  end
@@ -416,8 +418,27 @@ module Seabright
416
418
  true
417
419
  end
418
420
 
419
- def id_sym(cls=cname)
420
- "#{cls.split('::').last.downcase}_id".to_sym
421
+ def id_sym(cls=nil)
422
+ _old_id_sym(cls)
423
+ end
424
+
425
+ def _new_id_sym(cls=self.name)
426
+ (cls || self.name).foreign_key.to_sym
427
+ end
428
+
429
+ def convert_old_id_syms!
430
+ ol = _old_id_sym
431
+ nw = id_sym
432
+ each do |obj|
433
+ if obj.is_set?(ol)
434
+ obj.set(nw,get(ol))
435
+ obj.unset(ol)
436
+ end
437
+ end
438
+ end
439
+
440
+ def _old_id_sym(cls=self.name)
441
+ "#{(cls || self.name).split('::').last.downcase}_id".to_sym
421
442
  end
422
443
 
423
444
  def describe
@@ -45,8 +45,9 @@ module Seabright
45
45
  end
46
46
 
47
47
  def indexed(idx,num=-1,reverse=false)
48
+ kys = store.send(reverse ? :zrevrange : :zrange, index_key(idx), 0, num-1)
48
49
  out = Enumerator.new do |yielder|
49
- store.send(reverse ? :zrevrange : :zrange, index_key(idx), 0, num-1).each do |member|
50
+ kys.each do |member|
50
51
  if a = self.find_by_key(member)
51
52
  yielder << a
52
53
  end
@@ -1,5 +1,5 @@
1
1
  module Seabright
2
2
  class RedisObject
3
- VERSION = "1.3.0"
3
+ VERSION = "1.3.1b"
4
4
  end
5
5
  end
data/spec/base_spec.rb CHANGED
@@ -10,6 +10,11 @@ module ObjectTests
10
10
  class Doodad < RedisObject
11
11
 
12
12
  end
13
+ class Collidor < RedisObject
14
+ def new_id
15
+ "totsunique"
16
+ end
17
+ end
13
18
  end
14
19
 
15
20
  describe RedisObject do
@@ -38,6 +43,13 @@ describe RedisObject do
38
43
  obj.should_not be_nil
39
44
  end
40
45
 
46
+ it "should be found by complex matchers" do
47
+ obj = ObjectTests::User.find(user_id: "test")
48
+ obj.should_not be_nil
49
+ obj = ObjectTests::User.find(user_id: /test/)
50
+ obj.should_not be_nil
51
+ end
52
+
41
53
  it "can recollect objects" do
42
54
  ObjectTests::User.recollect!
43
55
  end
@@ -99,4 +111,9 @@ describe RedisObject do
99
111
  end
100
112
  end
101
113
 
114
+ it "detects id collisions" do
115
+ ObjectTests::Collidor.create
116
+ ObjectTests::Collidor.create
117
+ end
118
+
102
119
  end
data/spec/indices_spec.rb CHANGED
@@ -23,6 +23,7 @@ module IndexSpec
23
23
  end
24
24
 
25
25
  sort_by :a_number
26
+ sort_by :a_bool
26
27
 
27
28
  end
28
29
 
@@ -34,7 +35,7 @@ module IndexSpec
34
35
  it "indexes on integer field" do
35
36
 
36
37
  5.times do
37
- obj = IndexedObject.create(a_number: Random.rand(100))
38
+ obj = IndexedObject.create(a_number: Random.rand(100), a_bool: true)
38
39
  end
39
40
 
40
41
  IndexedObject.indexed(:a_number,3,true).count.should eq(3)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis_object
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1b
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Bragg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-06 00:00:00.000000000 Z
11
+ date: 2013-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: utf8_utils
@@ -163,9 +163,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
163
163
  version: 1.9.2
164
164
  required_rubygems_version: !ruby/object:Gem::Requirement
165
165
  requirements:
166
- - - ! '>='
166
+ - - ! '>'
167
167
  - !ruby/object:Gem::Version
168
- version: '0'
168
+ version: 1.3.1
169
169
  requirements: []
170
170
  rubyforge_project: redis_object
171
171
  rubygems_version: 2.0.3