redis_object 0.5.0 → 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +0 -2
- data/Gemfile +0 -4
- data/README.markdown +15 -24
- data/Rakefile +0 -8
- data/doc/Object.html +185 -0
- data/doc/Seabright.html +181 -0
- data/doc/Seabright/Adapter.html +442 -0
- data/doc/Seabright/Collection.html +797 -0
- data/doc/Seabright/Collections.html +635 -0
- data/doc/Seabright/Collections/ClassMethods.html +212 -0
- data/doc/Seabright/ExternalIndex.html +217 -0
- data/doc/Seabright/History.html +382 -0
- data/doc/Seabright/History/ClassMethods.html +276 -0
- data/doc/Seabright/Indices.html +324 -0
- data/doc/Seabright/Indices/ClassMethods.html +348 -0
- data/doc/Seabright/Keys.html +314 -0
- data/doc/Seabright/Keys/ClassMethods.html +276 -0
- data/doc/Seabright/ObjectBase.html +852 -0
- data/doc/Seabright/ObjectBase/ClassMethods.html +677 -0
- data/doc/Seabright/RedisObject.html +230 -0
- data/doc/Seabright/References.html +280 -0
- data/doc/Seabright/Storage.html +252 -0
- data/doc/Seabright/Storage/ClassMethods.html +276 -0
- data/doc/Seabright/Storage/MySQL.html +442 -0
- data/doc/Seabright/Storage/Redis.html +218 -0
- data/doc/Seabright/Template.html +212 -0
- data/doc/Seabright/Template/ClassMethods.html +166 -0
- data/doc/Seabright/Timestamps.html +292 -0
- data/doc/Seabright/Timestamps/ClassMethods.html +214 -0
- data/doc/Seabright/Types.html +410 -0
- data/doc/Seabright/Types/ClassMethods.html +308 -0
- data/doc/created.rid +17 -0
- data/doc/images/add.png +0 -0
- data/doc/images/brick.png +0 -0
- data/doc/images/brick_link.png +0 -0
- data/doc/images/bug.png +0 -0
- data/doc/images/bullet_black.png +0 -0
- data/doc/images/bullet_toggle_minus.png +0 -0
- data/doc/images/bullet_toggle_plus.png +0 -0
- data/doc/images/date.png +0 -0
- data/doc/images/delete.png +0 -0
- data/doc/images/find.png +0 -0
- data/doc/images/loadingAnimation.gif +0 -0
- data/doc/images/macFFBgHack.png +0 -0
- data/doc/images/package.png +0 -0
- data/doc/images/page_green.png +0 -0
- data/doc/images/page_white_text.png +0 -0
- data/doc/images/page_white_width.png +0 -0
- data/doc/images/plugin.png +0 -0
- data/doc/images/ruby.png +0 -0
- data/doc/images/tag_blue.png +0 -0
- data/doc/images/tag_green.png +0 -0
- data/doc/images/transparent.png +0 -0
- data/doc/images/wrench.png +0 -0
- data/doc/images/wrench_orange.png +0 -0
- data/doc/images/zoom.png +0 -0
- data/doc/index.html +125 -0
- data/doc/js/darkfish.js +153 -0
- data/doc/js/jquery.js +18 -0
- data/doc/js/navigation.js +142 -0
- data/doc/js/search.js +94 -0
- data/doc/js/search_index.js +1 -0
- data/doc/js/searcher.js +228 -0
- data/doc/rdoc.css +543 -0
- data/doc/table_of_contents.html +394 -0
- data/lib/redis_object.rb +1 -11
- data/lib/redis_object/base.rb +60 -210
- data/lib/redis_object/collection.rb +100 -130
- data/lib/redis_object/defaults.rb +8 -21
- data/lib/redis_object/ext/filters.rb +16 -34
- data/lib/redis_object/ext/triggers.rb +13 -75
- data/lib/redis_object/{experimental/history.rb → history.rb} +0 -0
- data/lib/redis_object/indices.rb +39 -44
- data/lib/redis_object/keys.rb +4 -4
- data/lib/redis_object/storage.rb +1 -30
- data/lib/redis_object/storage/adapter.rb +3 -6
- data/lib/redis_object/storage/redis.rb +3 -98
- data/lib/redis_object/timestamps.rb +21 -42
- data/lib/redis_object/types.rb +30 -172
- data/lib/redis_object/version.rb +1 -1
- data/redis_object.gemspec +0 -1
- data/spec/base_spec.rb +6 -41
- data/spec/spec_helper.rb +1 -32
- metadata +116 -111
- data/.coveralls.yml +0 -1
- data/.travis.yml +0 -5
- data/lib/redis_object/ext/script_cache.rb +0 -92
- data/lib/redis_object/ext/shardable.rb +0 -18
- data/lib/redis_object/ext/view_caching.rb +0 -258
- data/lib/redis_object/ext/views.rb +0 -102
- data/lib/redis_object/inheritance_tracking.rb +0 -23
- data/spec/adapter_spec.rb +0 -43
- data/spec/benchmark_spec.rb +0 -46
- data/spec/collections_spec.rb +0 -144
- data/spec/defaults_spec.rb +0 -56
- data/spec/filters_spec.rb +0 -29
- data/spec/indices_spec.rb +0 -45
- data/spec/rename_class_spec.rb +0 -96
- data/spec/timestamp_spec.rb +0 -28
- data/spec/trigger_spec.rb +0 -51
- data/spec/types_spec.rb +0 -103
- data/spec/view_caching_spec.rb +0 -130
- data/spec/views_spec.rb +0 -72
data/spec/timestamp_spec.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
|
3
|
-
module TriggerSpec
|
4
|
-
|
5
|
-
class TimestampedObject < RedisObject;end
|
6
|
-
|
7
|
-
class UnTimestampedObject < RedisObject
|
8
|
-
# time_matters_not!
|
9
|
-
end
|
10
|
-
|
11
|
-
describe Seabright::Triggers do
|
12
|
-
before do
|
13
|
-
RedisObject.store.flushdb
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should get recently created object" do
|
17
|
-
|
18
|
-
(1..5).each do |n|
|
19
|
-
TimestampedObject.create(n.to_s)
|
20
|
-
sleep Random.rand(1.0)
|
21
|
-
end
|
22
|
-
|
23
|
-
TimestampedObject.recently_created.first.id.should eq("5")
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|
data/spec/trigger_spec.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
|
3
|
-
module TriggerSpec
|
4
|
-
|
5
|
-
class TriggeredObject < RedisObject
|
6
|
-
|
7
|
-
int :raw_phone
|
8
|
-
bool :mailed_flag
|
9
|
-
bool :mail_was_sent_for_realz
|
10
|
-
date :srsly_updated
|
11
|
-
|
12
|
-
def track_phone_raw(k,v)
|
13
|
-
set(:raw_phone, v.gsub(/[^0-9]/,'').to_i)
|
14
|
-
end
|
15
|
-
|
16
|
-
trigger_on_set :phone, :track_phone_raw
|
17
|
-
|
18
|
-
def sent_mail(k,v)
|
19
|
-
set(:mail_was_sent_for_realz, true)
|
20
|
-
end
|
21
|
-
|
22
|
-
def updated_redundant(k,v)
|
23
|
-
set(:srsly_updated, Time.now)
|
24
|
-
end
|
25
|
-
|
26
|
-
trigger_on_set :mailed_flag, :sent_mail
|
27
|
-
trigger_on_update :updated_redundant
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
describe Seabright::Triggers do
|
32
|
-
before do
|
33
|
-
RedisObject.store.flushdb
|
34
|
-
end
|
35
|
-
|
36
|
-
it "triggers on a call" do
|
37
|
-
|
38
|
-
obj = TriggeredObject.create("trig")
|
39
|
-
|
40
|
-
obj.phone = "(970) 555-1212"
|
41
|
-
obj.raw_phone.should eq(9705551212)
|
42
|
-
success = obj.setnx(:mailed_flag,true)
|
43
|
-
success.should eq(true)
|
44
|
-
obj.mail_was_sent_for_realz.should eq(true)
|
45
|
-
success = obj.setnx(:mailed_flag,true)
|
46
|
-
success.should eq(false)
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
51
|
-
end
|
data/spec/types_spec.rb
DELETED
@@ -1,103 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
|
3
|
-
module TypeSpec
|
4
|
-
|
5
|
-
TestValues = {
|
6
|
-
date: Date.today,
|
7
|
-
number: 27,
|
8
|
-
int: 356192,
|
9
|
-
float: 72.362517,
|
10
|
-
bool: true,
|
11
|
-
boolean: false,
|
12
|
-
array: ["test1","test2"],
|
13
|
-
json: {test1: true, test2: "false"}
|
14
|
-
}
|
15
|
-
|
16
|
-
TestData = TestValues.inject({}){|acc,(k,v)| acc["a_#{k}".to_sym] = v; acc }
|
17
|
-
|
18
|
-
class TypedObject < RedisObject
|
19
|
-
TestValues.keys.each do |type|
|
20
|
-
send(type.to_sym,"a_#{type}".to_sym)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
class TypedChild < TypedObject; end
|
25
|
-
|
26
|
-
describe Seabright::Types do
|
27
|
-
before do
|
28
|
-
RedisObject.store.flushdb
|
29
|
-
end
|
30
|
-
|
31
|
-
it "can be created via data packet" do
|
32
|
-
|
33
|
-
obj = TypedObject.create(TestData)
|
34
|
-
|
35
|
-
TestData.each do |k,v|
|
36
|
-
obj.get(k).should eq(v)
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
it "inherits types" do
|
42
|
-
|
43
|
-
obj = TypedChild.create(TestData)
|
44
|
-
|
45
|
-
TestData.each do |k,v|
|
46
|
-
obj.get(k).should eq(v)
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
it "can be instantiated (new) via data packet" do
|
52
|
-
|
53
|
-
obj = TypedObject.new(TestData)
|
54
|
-
|
55
|
-
TestData.each do |k,v|
|
56
|
-
obj.get(k).should eq(v)
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
it "can be created via individual sets" do
|
62
|
-
|
63
|
-
obj = TypedObject.new
|
64
|
-
|
65
|
-
TestData.each do |k,v|
|
66
|
-
obj.set(k,v)
|
67
|
-
obj.get(k).should eq(v)
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|
71
|
-
|
72
|
-
it "gets correct values after being found" do
|
73
|
-
|
74
|
-
objc = TypedObject.create(TestData)
|
75
|
-
obj = TypedObject.find(objc.id)
|
76
|
-
|
77
|
-
TestData.each do |k,v|
|
78
|
-
obj.get(k).should eq(v)
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
82
|
-
|
83
|
-
it "nullifies non-date date value" do
|
84
|
-
|
85
|
-
obj = TypedObject.new
|
86
|
-
|
87
|
-
obj.a_date = "sjahfgasjfg"
|
88
|
-
obj.a_date.should eq(nil)
|
89
|
-
|
90
|
-
end
|
91
|
-
|
92
|
-
it "describes itself" do
|
93
|
-
|
94
|
-
obj = TypedObject.create(TestData)
|
95
|
-
objc = TypedChild.create(TestData)
|
96
|
-
|
97
|
-
desc = TypedObject.describe
|
98
|
-
TypedObject.dump_schema(File.open("/tmp/redisobject_dump_test","w"))
|
99
|
-
|
100
|
-
end
|
101
|
-
|
102
|
-
end
|
103
|
-
end
|
data/spec/view_caching_spec.rb
DELETED
@@ -1,130 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
|
3
|
-
module ViewCachingSpec
|
4
|
-
|
5
|
-
TestValues = {
|
6
|
-
date: Date.today,
|
7
|
-
number: 27,
|
8
|
-
int: 356192,
|
9
|
-
float: 72.362517,
|
10
|
-
bool: true,
|
11
|
-
# boolean: false,
|
12
|
-
# array: [:test1,:test2],
|
13
|
-
json: {test1: true, test2: "false"}
|
14
|
-
}
|
15
|
-
|
16
|
-
TestData = TestValues.inject({}){|acc,(k,v)| acc["a_#{k}".to_sym] = v; acc }
|
17
|
-
|
18
|
-
class TypedObject < RedisObject
|
19
|
-
|
20
|
-
named_view :miss_json, :a_number
|
21
|
-
named_view :aggregated, :a_float, :a_bool, :aggregate
|
22
|
-
cache_view :aggregated
|
23
|
-
cache_view :miss_json
|
24
|
-
|
25
|
-
TestValues.keys.each do |type|
|
26
|
-
send(type.to_sym,"a_#{type}".to_sym)
|
27
|
-
end
|
28
|
-
|
29
|
-
def aggregate
|
30
|
-
a_number + a_int
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
class Container < RedisObject
|
36
|
-
|
37
|
-
invalidate_downstream :TypedObject
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
class Baby < RedisObject
|
42
|
-
|
43
|
-
invalidate_upstream :TypedObject
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
describe Seabright::ViewCaching do
|
48
|
-
|
49
|
-
before do
|
50
|
-
RedisObject.store.flushdb
|
51
|
-
@obj = TypedObject.create(TestData)
|
52
|
-
@dad = Container.create("daddy")
|
53
|
-
@dad << @obj
|
54
|
-
@baby = Baby.create("mama")
|
55
|
-
@obj << @baby
|
56
|
-
end
|
57
|
-
|
58
|
-
it "generates view" do
|
59
|
-
|
60
|
-
@obj.view_as_hash(:aggregated).should be_a(Hash)
|
61
|
-
@obj.view_as_json(:aggregated).should be_a(String)
|
62
|
-
|
63
|
-
end
|
64
|
-
|
65
|
-
it "gets cached view on second access" do
|
66
|
-
|
67
|
-
@obj.view_as_hash(:aggregated).should be_a(Hash)
|
68
|
-
@obj.view_as_json(:aggregated).should be_a(String)
|
69
|
-
@obj.view_is_cached?(:aggregated).should eq(true)
|
70
|
-
@obj.view_as_hash(:aggregated).should be_a(Hash)
|
71
|
-
@obj.view_as_json(:aggregated).should be_a(String)
|
72
|
-
|
73
|
-
@obj.view_as_json(:miss_json).should be_a(String)
|
74
|
-
|
75
|
-
end
|
76
|
-
|
77
|
-
it "generates view" do
|
78
|
-
|
79
|
-
@obj.regenerate_cached_views!
|
80
|
-
@obj.view_is_cached?(:aggregated).should eq(true)
|
81
|
-
|
82
|
-
end
|
83
|
-
|
84
|
-
it "caches are invalidated" do
|
85
|
-
|
86
|
-
@obj.view_as_hash(:aggregated).should be_a(Hash)
|
87
|
-
|
88
|
-
@obj.view_is_cached?(:aggregated).should eq(true)
|
89
|
-
|
90
|
-
@obj.invalidate_cached_views!
|
91
|
-
|
92
|
-
@obj.view_is_cached?(:aggregated).should eq(false)
|
93
|
-
|
94
|
-
@obj.view_as_hash(:aggregated).should be_a(Hash)
|
95
|
-
|
96
|
-
@obj.view_is_cached?(:aggregated).should eq(true)
|
97
|
-
|
98
|
-
@obj.set(:demolisher, "smash")
|
99
|
-
#
|
100
|
-
# @obj.view_is_cached?(:aggregated).should eq(false)
|
101
|
-
|
102
|
-
|
103
|
-
end
|
104
|
-
|
105
|
-
it "invalidates up/down stream" do
|
106
|
-
|
107
|
-
@obj.view_as_hash(:aggregated).should be_a(Hash)
|
108
|
-
|
109
|
-
@obj.view_is_cached?(:aggregated).should eq(true)
|
110
|
-
|
111
|
-
@baby.set(:demolisher, "smash")
|
112
|
-
|
113
|
-
# sleep 1
|
114
|
-
#
|
115
|
-
# TypedObject.find(@obj.id).view_is_cached?(:aggregated).should eq(false)
|
116
|
-
|
117
|
-
@obj.view_as_hash(:aggregated).should be_a(Hash)
|
118
|
-
|
119
|
-
@obj.view_is_cached?(:aggregated).should eq(true)
|
120
|
-
|
121
|
-
@dad.set(:demolisher, "smash")
|
122
|
-
|
123
|
-
# sleep 1
|
124
|
-
#
|
125
|
-
# TypedObject.find(@obj.id).view_is_cached?(:aggregated).should eq(false)
|
126
|
-
|
127
|
-
end
|
128
|
-
|
129
|
-
end
|
130
|
-
end
|
data/spec/views_spec.rb
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
|
3
|
-
module ViewSpec
|
4
|
-
|
5
|
-
TestValues = {
|
6
|
-
date: Date.today,
|
7
|
-
number: 27,
|
8
|
-
int: 356192,
|
9
|
-
float: 72.362517,
|
10
|
-
bool: true
|
11
|
-
}
|
12
|
-
|
13
|
-
TestData = TestValues.inject({}){|acc,(k,v)| acc["a_#{k}".to_sym] = v; acc }
|
14
|
-
|
15
|
-
class ViewedObject < RedisObject
|
16
|
-
|
17
|
-
named_view :bare, :a_float, :a_bool
|
18
|
-
named_view :aggregated, :a_float, :a_bool, :aggregate
|
19
|
-
named_view :aggregated_only, :method => :aggregate
|
20
|
-
named_view :proc, {:lambda => Proc.new {|o| o.get(:a_bool) } }, :aggregate
|
21
|
-
named_view :hashy, {:hesher => :a_number }, :aggregate
|
22
|
-
|
23
|
-
TestValues.keys.each do |type|
|
24
|
-
send(type.to_sym,"a_#{type}".to_sym)
|
25
|
-
end
|
26
|
-
|
27
|
-
def aggregate
|
28
|
-
a_number + a_int
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
describe Seabright::Views do
|
34
|
-
|
35
|
-
before do
|
36
|
-
RedisObject.store.flushdb
|
37
|
-
@obj = ViewedObject.create(TestData)
|
38
|
-
end
|
39
|
-
|
40
|
-
it "generates view" do
|
41
|
-
|
42
|
-
@obj.view_as_hash(:bare).should be_a(Hash)
|
43
|
-
@obj.view_as_json(:bare).should be_a(String)
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
it "generates mthod-only view" do
|
48
|
-
|
49
|
-
@obj.view_as_hash(:aggregated_only).should be_a(Fixnum)
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
it "views methods properly" do
|
54
|
-
|
55
|
-
@obj.view_as_hash(:aggregated)["aggregate"].should eq(TestData[:a_number] + TestData[:a_int])
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
it "executes procs within view" do
|
60
|
-
|
61
|
-
@obj.view_as_json(:proc).should be_a(String)
|
62
|
-
|
63
|
-
end
|
64
|
-
|
65
|
-
it "generates hashes within view" do
|
66
|
-
|
67
|
-
@obj.view_as_hash(:hashy).should be_a(Hash)
|
68
|
-
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
end
|