redis_object 1.4.6 → 1.4.7

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
- YjUwNzhkOGUyMjk3Njc5MTA4OGI2MmJmYmM2YjZiNmUwNGYyNTAwYQ==
4
+ ZjZmYjVhYmM1NDZmZTY1MTgyZWE3NDE3ZmYxZTFkOTAyNjM1OGJkYg==
5
5
  data.tar.gz: !binary |-
6
- OWQzMGVkOTRiNmIxMzMyNGVmYTEwYTcyNTNiYzNkZjE4ZTYyZWU4NA==
7
- !binary "U0hBNTEy":
6
+ YmViNzk2OTIyMTFjNWJhM2Q5MDc5MzZmOTNjMWYxNWNlYmVkMDlhYw==
7
+ SHA512:
8
8
  metadata.gz: !binary |-
9
- ZmY1OTNkNjc0YTZkYzVlNTdhNGU3YTE2ZmE0MTIwOTVlMjdjNWYxMjQ4YTZh
10
- NTc3ZmVkNmRjMDkwYTgyYTI5NTFkNGY4YTNlYmVlZjAyYzg5ZjdkNmRiZWY5
11
- ZWIxMmI2ODgwZTRkOTMwNWQxY2M4NGRiYTJlYWFmZjlhODEzZTU=
9
+ NmI0NTBiOWEyMjliMzIyMTUxOTM0NDFmOWRkMmIwOTRlYWE2ZTEzYWFhNmRh
10
+ NzA5MmQ2NTcwYjc2YWE2MzhiMDM5MTlkYjQyNTU1ZGRlMzA3MDk5NGVkYTY5
11
+ Nzg0YTQ4NTZiZGExOTU1NjNkYTIwZDFlMWVlNDc5Y2FjOTQwNzk=
12
12
  data.tar.gz: !binary |-
13
- NGViMjUzNWIxZjYxZWUzYjU3NGY0MzEwNjkyMmRmNWU5NWI3ZGUwZWFjY2Mw
14
- YWEyZjAzZGU3MjExNGY2ZDBjNDUxZDY2ZmYxYWY4MmVhNTFjYjA5NjMxMzgy
15
- OTQ2ZGUwODZhNDYxNDliMzM3MmI5ZDhhYjY0ZDk2N2JmNWJiZmY=
13
+ YjkwMDRmN2E2OTcwMjQ0NmM4ZjlmM2RlNmMxM2NiNTczMzRmMjA4ZjE4YzYy
14
+ ODNkYWEzZDQ1NWY1MjFkZTFiMmI0OTM1MDcxYzVkYjYyNjdkNDQ0YWUxMjNm
15
+ M2E5OTAwOTUyYmZjOTg0YzZkYWU0MjA0NjQ4ZDJjNGM1OWVjN2U=
data/.travis.yml CHANGED
@@ -3,4 +3,7 @@ rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
5
  env:
6
- - "TEST_DB=14"
6
+ - "TEST_DB=14"
7
+ addons:
8
+ code_climate:
9
+ repo_token: "8b629930bc603ff8abbbe21d72914c991d265959abdd284a638e9d8366e9ade5"
data/Gemfile CHANGED
@@ -5,6 +5,7 @@ group :test do
5
5
  gem 'rspec'
6
6
  gem 'coveralls', require: false
7
7
  gem 'fuubar'
8
+ gem "codeclimate-test-reporter", require: nil
8
9
  end
9
10
 
10
11
  group :development, :test do
@@ -369,26 +369,109 @@ module Seabright
369
369
  end
370
370
  end
371
371
  return out".gsub(/\t/,'').freeze
372
+
373
+ RedisObject::ScriptSources::OrMatcher = "local itms = redis.call('SMEMBERS',KEYS[1])
374
+ local out = {}
375
+ local matchers = {}
376
+ local matcher = {}
377
+ local mod
378
+ for i=1,#ARGV do
379
+ mod = i % 2
380
+ if mod == 1 then
381
+ matcher[1] = ARGV[i]
382
+ else
383
+ matcher[2] = ARGV[i]
384
+ table.insert(matchers,matcher)
385
+ matcher = {}
386
+ end
387
+ end
388
+
389
+ local val
390
+ local good
391
+ local pattern
392
+ for i, v in ipairs(itms) do
393
+ good = false
394
+ for n=1,#matchers do
395
+ val = redis.call('HGET',v..'_h',matchers[n][1])
396
+ if val then
397
+ if matchers[n][2]:find('^pattern:') then
398
+ pattern = matchers[n][2]:gsub('^pattern:','')
399
+ if val:match(pattern) then
400
+ good = true
401
+ break
402
+ else
403
+ good = good
404
+ end
405
+ elseif matchers[n][2]:find('^ipattern:') then
406
+ pattern = matchers[n][2]:gsub('^ipattern:',''):lower()
407
+ if val:lower():match(pattern) then
408
+ good = true
409
+ break
410
+ else
411
+ good = good
412
+ end
413
+ else
414
+ if val == matchers[n][2] then
415
+ good = true
416
+ break
417
+ end
418
+ end
419
+ else
420
+ if matchers[n][2] == '#{NilPattern}' then
421
+ good = good
422
+ break
423
+ else
424
+ good = false
425
+ end
426
+ end
427
+ end
428
+ if good == true then
429
+ table.insert(out,itms[i])
430
+ end
431
+ end
432
+ return out".gsub(/\t/,'').freeze
372
433
 
373
- def match(pkt)
374
- mtchr = pkt.keys.count > 1 ? :MultiMatcher : :Matcher
375
- pkt = pkt.flatten.map do |i|
376
- case i
434
+ def match(pkt, use_or=false)
435
+ if use_or
436
+ mtchr = :OrMatcher
437
+ else
438
+ mtchr = pkt.keys.count > 1 ? :MultiMatcher : :Matcher
439
+ end
440
+ pkt = pkt.flatten.reduce([]) do |i,v|
441
+ x = case v
377
442
  when Regexp
378
- convert_regex_to_lua(i)
443
+ convert_regex_to_lua(v)
444
+ when Array
445
+ raise ArgumentError.new("An array can only be used with the find_or method") unless use_or
446
+ inject_key(i.last, v)
379
447
  when NilClass
380
448
  NilPattern
381
449
  else
382
- i.to_s
450
+ v.to_s
383
451
  end
452
+ i << x
453
+ i
384
454
  end
385
- kys = run_script(mtchr,[plname],pkt)
455
+ kys = run_script(mtchr,[plname],pkt.flatten)
386
456
  ListEnumerator.new(kys) do |y|
387
457
  kys.each do |k|
388
458
  y << find(k)
389
459
  end
390
460
  end
391
461
  end
462
+
463
+ def inject_key(key,list)
464
+ out = []
465
+ list.each do |i|
466
+ if i == list.first
467
+ out << i
468
+ else
469
+ out << key
470
+ out << i
471
+ end
472
+ end
473
+ out
474
+ end
392
475
 
393
476
  def convert_regex_to_lua(reg)
394
477
  "#{reg.casefold? ? "i" : ""}pattern:#{reg.source.gsub("\\","")}"
@@ -403,10 +486,22 @@ module Seabright
403
486
  end
404
487
  nil
405
488
  end
489
+
490
+ def or_grab(ident)
491
+ case ident
492
+ when Hash
493
+ return match(ident, true)
494
+ end
495
+ nil
496
+ end
406
497
 
407
498
  def find(ident)
408
499
  grab(ident)
409
500
  end
501
+
502
+ def or_find(ident)
503
+ or_grab(ident)
504
+ end
410
505
 
411
506
  def exists?(k)
412
507
  store.exists(self.hkey(k)) || store.exists(self.reserve_key(k))
@@ -1,5 +1,5 @@
1
1
  module Seabright
2
2
  class RedisObject
3
- VERSION = "1.4.6"
3
+ VERSION = "1.4.7"
4
4
  end
5
5
  end
data/spec/base_spec.rb CHANGED
@@ -57,6 +57,50 @@ describe RedisObject do
57
57
  obj = ObjectTests::User.find(user_id: /Test/, blah: nil)
58
58
  obj.first.should be_nil
59
59
  end
60
+
61
+ it "should be found by or matchers" do
62
+ obj = ObjectTests::User.new("sico")
63
+ obj.save
64
+ obj.foo = "bar!"
65
+ obj2 = ObjectTests::User.new("notsico")
66
+ obj2.save
67
+ obj2.stuff = "woo!"
68
+ res = ObjectTests::User.or_find(stuff: "woo!", foo: "bar!")
69
+ res.count.should eq(2)
70
+ end
71
+
72
+ it "should be found by complex or matchers" do
73
+ obj = ObjectTests::User.new("sico")
74
+ obj.save
75
+ obj.foo = "bar!"
76
+ obj2 = ObjectTests::User.new("notsico")
77
+ obj2.save
78
+ obj2.stuff = "woo!"
79
+ res = ObjectTests::User.or_find(stuff: /Woo!/i, foo: "bar!")
80
+ res.count.should eq(2)
81
+ res = ObjectTests::User.or_find(stuff: /Woo!/i, foo: /bar!/i)
82
+ res.count.should eq(2)
83
+ res = ObjectTests::User.or_find(stuff: /Woo(.*)/i, foo: /bar!/i)
84
+ res.count.should eq(2)
85
+ res = ObjectTests::User.or_find(stuff: /woo!/i, foo: /Bar!/)
86
+ res.count.should eq(1)
87
+ end
88
+
89
+ it "should be found by or-matcher using same key" do
90
+ obj = ObjectTests::User.new("sico")
91
+ obj.save
92
+ obj.foo = "bar!"
93
+ obj2 = ObjectTests::User.new("notsico")
94
+ obj2.save
95
+ obj2.foo = "woo!"
96
+ res = ObjectTests::User.or_find(foo: ["woo!","bar!"])
97
+ res.count.should eq(2)
98
+ end
99
+
100
+ it "should raise an ArguemntError when passing array to find" do
101
+ expect { ObjectTests::User.find(user_id: ["test","sico"]) }.to raise_error(ArgumentError)
102
+ expect { ObjectTests::User.or_find(user_id: ["test","sico"]) }.not_to raise_error
103
+ end
60
104
 
61
105
  it "should be found by nil matchers" do
62
106
  obj = ObjectTests::User.find(blah: nil)
data/spec/spec_helper.rb CHANGED
@@ -8,6 +8,9 @@ require 'rspec'
8
8
  require 'simplecov'
9
9
  require 'coveralls'
10
10
 
11
+ require "codeclimate-test-reporter"
12
+ CodeClimate::TestReporter.start
13
+
11
14
  SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
12
15
  SimpleCov::Formatter::HTMLFormatter,
13
16
  Coveralls::SimpleCov::Formatter
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.4.6
4
+ version: 1.4.7
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-08-21 00:00:00.000000000 Z
11
+ date: 2013-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: utf8_utils
@@ -170,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
170
170
  version: '0'
171
171
  requirements: []
172
172
  rubyforge_project: redis_object
173
- rubygems_version: 2.0.3
173
+ rubygems_version: 2.1.4
174
174
  signing_key:
175
175
  specification_version: 4
176
176
  summary: Maps arbitrary objects to a Redis store with indices and smart retrieval