redis_object 1.4.3 → 1.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/redis_object/base.rb +4 -1
- data/lib/redis_object/experimental/dumping.rb +54 -9
- data/lib/redis_object/version.rb +1 -1
- data/spec/base_spec.rb +7 -0
- data/spec/dumping_spec.rb +23 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZmEzMTFmMmU3MTcyZDllYzYwYjQ0YzM5ZGE1ZGQ4NjI5MDI2MjVmYw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YTMzYTdjZDg4ZWIzNDE1ODliYTY0N2I5YTYwYTQ5ZGUyNjY5MjFhOQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NzdkNzFlNjc4OWM3ZWVhMmI2YzBjMWZiMDhhMmZjNjliOWI2NzhhNDZiOThl
|
10
|
+
NWYzYzhiMzJiYzE4MTdlMjZiZWU3MDBhMzk4NDBiOTdlM2Y4MTgzMmI1Mzk5
|
11
|
+
Njk0YjRhZmJiMWEzYjk3YWNmYjQwYmJhNTUyNzdmOWI1ZDdhYmI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MzViYzViZDBjOTFlOTVkZmVkZjg2ZTFmNWJkM2ZmY2I2NjUwMzhmNjI3MzYz
|
14
|
+
M2Q2OTllODgwZGUwZWM1ZTFmYTc3Yjg5ZWRmNTJjYzQ4MjA2ZTJmOTk1ZjI3
|
15
|
+
ZWVkNDk0NmMxYmE4YWYwM2VjY2ZlYjhlOTMxMGJlZmY4NjAzYTI=
|
data/lib/redis_object/base.rb
CHANGED
@@ -334,17 +334,20 @@ module Seabright
|
|
334
334
|
good = good
|
335
335
|
else
|
336
336
|
good = false
|
337
|
+
break
|
337
338
|
end
|
338
339
|
else
|
339
340
|
if val ~= matchers[n][2] then
|
340
341
|
good = false
|
342
|
+
break
|
341
343
|
end
|
342
344
|
end
|
343
345
|
else
|
344
346
|
if matchers[n][2] == '#{NilPattern}' then
|
345
|
-
good =
|
347
|
+
good = good
|
346
348
|
else
|
347
349
|
good = false
|
350
|
+
break
|
348
351
|
end
|
349
352
|
end
|
350
353
|
end
|
@@ -4,21 +4,32 @@ require 'active_support/core_ext/time/calculations'
|
|
4
4
|
module Seabright
|
5
5
|
class RedisObject
|
6
6
|
|
7
|
-
def self.dump_everything(
|
7
|
+
def self.dump_everything(dump_format=:hash)
|
8
8
|
out = {}
|
9
9
|
ObjectSpace.enum_for(:each_object, class << RedisObject; self; end).each do |cls|
|
10
10
|
unless cls == RedisObject
|
11
|
-
out
|
12
|
-
out[cls.name][:objects] = cls.all.map do |obj|
|
13
|
-
obj.full_hash_dump
|
14
|
-
end
|
11
|
+
out.merge! cls.dump_all(:hash)
|
15
12
|
end
|
16
13
|
end
|
17
|
-
|
14
|
+
Dumping.format_dump out, dump_format
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.load_dump(str,dump_format=:hash)
|
18
|
+
case dump_format
|
19
|
+
when :hash
|
20
|
+
load_dump_from_hash str
|
21
|
+
when :yaml, :yml
|
22
|
+
load_dump_from_yaml str
|
23
|
+
# JSON format is not ready yet!
|
24
|
+
# when :json
|
25
|
+
# load_dump_from_json str
|
26
|
+
else
|
27
|
+
raise "Unknown dump format."
|
28
|
+
end
|
18
29
|
end
|
19
30
|
|
20
|
-
def self.
|
21
|
-
|
31
|
+
def self.load_data(dat)
|
32
|
+
dat.each do |(k,v)|
|
22
33
|
if klass = RedisObject.deep_const_get(k)
|
23
34
|
if v[:objects]
|
24
35
|
v[:objects].each do |o|
|
@@ -29,6 +40,19 @@ module Seabright
|
|
29
40
|
end
|
30
41
|
end
|
31
42
|
|
43
|
+
def self.load_dump_from_yaml(str)
|
44
|
+
load_data Psych.load(str)
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.load_dump_from_hash(str)
|
48
|
+
load_data str
|
49
|
+
end
|
50
|
+
|
51
|
+
# JSON format is not ready yet!
|
52
|
+
# def self.load_dump_from_json(str)
|
53
|
+
# load_data Yajl::Parser.new(symbolize_keys: true).parse(str)
|
54
|
+
# end
|
55
|
+
|
32
56
|
def self.load_object(klass,pkt)
|
33
57
|
Log.debug "Loading a #{klass.name}: #{pkt.inspect}"
|
34
58
|
cols = nil
|
@@ -59,6 +83,20 @@ module Seabright
|
|
59
83
|
# end
|
60
84
|
# end
|
61
85
|
|
86
|
+
def self.format_dump(dump,format=:hash)
|
87
|
+
case format
|
88
|
+
when :hash
|
89
|
+
return dump
|
90
|
+
when :yaml, :yml
|
91
|
+
return Psych.dump(dump)
|
92
|
+
# JSON format is not ready yet!
|
93
|
+
# when :json
|
94
|
+
# return Yajl::Encoder.encode(dump)
|
95
|
+
else
|
96
|
+
return dump
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
62
100
|
def full_hash_dump
|
63
101
|
store.hgetall(hkey).inject({}) {|acc,(k,v)| acc[k.to_sym] = enforce_format(k,v); acc }.merge(dump_collections)
|
64
102
|
end
|
@@ -83,7 +121,14 @@ module Seabright
|
|
83
121
|
|
84
122
|
module ClassMethods
|
85
123
|
|
86
|
-
|
124
|
+
def dump_all(dump_format=:hash)
|
125
|
+
out = {}
|
126
|
+
out[self.name] = {}
|
127
|
+
out[self.name][:objects] = all.map do |obj|
|
128
|
+
obj.full_hash_dump
|
129
|
+
end
|
130
|
+
Dumping.format_dump out, dump_format
|
131
|
+
end
|
87
132
|
|
88
133
|
end
|
89
134
|
|
data/lib/redis_object/version.rb
CHANGED
data/spec/base_spec.rb
CHANGED
@@ -55,6 +55,13 @@ describe RedisObject do
|
|
55
55
|
obj.first.should_not be_nil
|
56
56
|
end
|
57
57
|
|
58
|
+
it "should be found/not-found by nil composite matchers" do
|
59
|
+
obj = ObjectTests::User.find(blah: nil, user_id: "test")
|
60
|
+
obj.first.should_not be_nil
|
61
|
+
obj = ObjectTests::User.find(blah: nil, user_id: "blah")
|
62
|
+
obj.first.should be_nil
|
63
|
+
end
|
64
|
+
|
58
65
|
it "should be found by regex matchers that do not exist as keys" do
|
59
66
|
obj = ObjectTests::User.find(blah: /test/)
|
60
67
|
obj.first.should be_nil
|
data/spec/dumping_spec.rb
CHANGED
@@ -41,19 +41,39 @@ module DumpingSpec
|
|
41
41
|
|
42
42
|
it "can dump errthing" do
|
43
43
|
|
44
|
-
r = RedisObject.dump_everything
|
44
|
+
r = RedisObject.dump_everything(:yml)
|
45
45
|
r.size.should > 100
|
46
|
+
# r = RedisObject.dump_everything(:json)
|
47
|
+
# r.size.should > 100
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
it "can dump a single class" do
|
52
|
+
|
53
|
+
r = RedisObject.dump_everything(:yml)
|
54
|
+
r.size.should > 100
|
55
|
+
d = DumpableObject.dump_all(:yml)
|
56
|
+
d.size.should > 100
|
57
|
+
d.size.should < r.size
|
58
|
+
# r = RedisObject.dump_everything(:json)
|
59
|
+
# r.size.should > 100
|
46
60
|
|
47
61
|
end
|
48
62
|
|
49
63
|
it "can load back in a dump" do
|
50
64
|
|
51
|
-
r = RedisObject.dump_everything
|
65
|
+
r = RedisObject.dump_everything(:yml)
|
52
66
|
r.size.should > 100
|
53
67
|
RedisObject.store.flushdb
|
54
|
-
RedisObject.load_dump r
|
68
|
+
RedisObject.load_dump r, :yml
|
55
69
|
DumpableObject.latest.generic_objects.count.should eq(1)
|
56
70
|
|
71
|
+
# r = RedisObject.dump_everything(:json)
|
72
|
+
# r.size.should > 100
|
73
|
+
# RedisObject.store.flushdb
|
74
|
+
# RedisObject.load_dump r, :json
|
75
|
+
# DumpableObject.latest.generic_objects.count.should eq(1)
|
76
|
+
|
57
77
|
end
|
58
78
|
|
59
79
|
end
|
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.
|
4
|
+
version: 1.4.5
|
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-
|
11
|
+
date: 2013-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: utf8_utils
|