redis_object 0.5.0 → 1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. data/.gitignore +0 -2
  2. data/Gemfile +0 -4
  3. data/README.markdown +15 -24
  4. data/Rakefile +0 -8
  5. data/doc/Object.html +185 -0
  6. data/doc/Seabright.html +181 -0
  7. data/doc/Seabright/Adapter.html +442 -0
  8. data/doc/Seabright/Collection.html +797 -0
  9. data/doc/Seabright/Collections.html +635 -0
  10. data/doc/Seabright/Collections/ClassMethods.html +212 -0
  11. data/doc/Seabright/ExternalIndex.html +217 -0
  12. data/doc/Seabright/History.html +382 -0
  13. data/doc/Seabright/History/ClassMethods.html +276 -0
  14. data/doc/Seabright/Indices.html +324 -0
  15. data/doc/Seabright/Indices/ClassMethods.html +348 -0
  16. data/doc/Seabright/Keys.html +314 -0
  17. data/doc/Seabright/Keys/ClassMethods.html +276 -0
  18. data/doc/Seabright/ObjectBase.html +852 -0
  19. data/doc/Seabright/ObjectBase/ClassMethods.html +677 -0
  20. data/doc/Seabright/RedisObject.html +230 -0
  21. data/doc/Seabright/References.html +280 -0
  22. data/doc/Seabright/Storage.html +252 -0
  23. data/doc/Seabright/Storage/ClassMethods.html +276 -0
  24. data/doc/Seabright/Storage/MySQL.html +442 -0
  25. data/doc/Seabright/Storage/Redis.html +218 -0
  26. data/doc/Seabright/Template.html +212 -0
  27. data/doc/Seabright/Template/ClassMethods.html +166 -0
  28. data/doc/Seabright/Timestamps.html +292 -0
  29. data/doc/Seabright/Timestamps/ClassMethods.html +214 -0
  30. data/doc/Seabright/Types.html +410 -0
  31. data/doc/Seabright/Types/ClassMethods.html +308 -0
  32. data/doc/created.rid +17 -0
  33. data/doc/images/add.png +0 -0
  34. data/doc/images/brick.png +0 -0
  35. data/doc/images/brick_link.png +0 -0
  36. data/doc/images/bug.png +0 -0
  37. data/doc/images/bullet_black.png +0 -0
  38. data/doc/images/bullet_toggle_minus.png +0 -0
  39. data/doc/images/bullet_toggle_plus.png +0 -0
  40. data/doc/images/date.png +0 -0
  41. data/doc/images/delete.png +0 -0
  42. data/doc/images/find.png +0 -0
  43. data/doc/images/loadingAnimation.gif +0 -0
  44. data/doc/images/macFFBgHack.png +0 -0
  45. data/doc/images/package.png +0 -0
  46. data/doc/images/page_green.png +0 -0
  47. data/doc/images/page_white_text.png +0 -0
  48. data/doc/images/page_white_width.png +0 -0
  49. data/doc/images/plugin.png +0 -0
  50. data/doc/images/ruby.png +0 -0
  51. data/doc/images/tag_blue.png +0 -0
  52. data/doc/images/tag_green.png +0 -0
  53. data/doc/images/transparent.png +0 -0
  54. data/doc/images/wrench.png +0 -0
  55. data/doc/images/wrench_orange.png +0 -0
  56. data/doc/images/zoom.png +0 -0
  57. data/doc/index.html +125 -0
  58. data/doc/js/darkfish.js +153 -0
  59. data/doc/js/jquery.js +18 -0
  60. data/doc/js/navigation.js +142 -0
  61. data/doc/js/search.js +94 -0
  62. data/doc/js/search_index.js +1 -0
  63. data/doc/js/searcher.js +228 -0
  64. data/doc/rdoc.css +543 -0
  65. data/doc/table_of_contents.html +394 -0
  66. data/lib/redis_object.rb +1 -11
  67. data/lib/redis_object/base.rb +60 -210
  68. data/lib/redis_object/collection.rb +100 -130
  69. data/lib/redis_object/defaults.rb +8 -21
  70. data/lib/redis_object/ext/filters.rb +16 -34
  71. data/lib/redis_object/ext/triggers.rb +13 -75
  72. data/lib/redis_object/{experimental/history.rb → history.rb} +0 -0
  73. data/lib/redis_object/indices.rb +39 -44
  74. data/lib/redis_object/keys.rb +4 -4
  75. data/lib/redis_object/storage.rb +1 -30
  76. data/lib/redis_object/storage/adapter.rb +3 -6
  77. data/lib/redis_object/storage/redis.rb +3 -98
  78. data/lib/redis_object/timestamps.rb +21 -42
  79. data/lib/redis_object/types.rb +30 -172
  80. data/lib/redis_object/version.rb +1 -1
  81. data/redis_object.gemspec +0 -1
  82. data/spec/base_spec.rb +6 -41
  83. data/spec/spec_helper.rb +1 -32
  84. metadata +116 -111
  85. data/.coveralls.yml +0 -1
  86. data/.travis.yml +0 -5
  87. data/lib/redis_object/ext/script_cache.rb +0 -92
  88. data/lib/redis_object/ext/shardable.rb +0 -18
  89. data/lib/redis_object/ext/view_caching.rb +0 -258
  90. data/lib/redis_object/ext/views.rb +0 -102
  91. data/lib/redis_object/inheritance_tracking.rb +0 -23
  92. data/spec/adapter_spec.rb +0 -43
  93. data/spec/benchmark_spec.rb +0 -46
  94. data/spec/collections_spec.rb +0 -144
  95. data/spec/defaults_spec.rb +0 -56
  96. data/spec/filters_spec.rb +0 -29
  97. data/spec/indices_spec.rb +0 -45
  98. data/spec/rename_class_spec.rb +0 -96
  99. data/spec/timestamp_spec.rb +0 -28
  100. data/spec/trigger_spec.rb +0 -51
  101. data/spec/types_spec.rb +0 -103
  102. data/spec/view_caching_spec.rb +0 -130
  103. data/spec/views_spec.rb +0 -72
@@ -1,23 +0,0 @@
1
- module Seabright
2
- module InheritanceTracking
3
-
4
- module ClassMethods
5
- def inherited(child_class)
6
- child_classes_set.add(child_class)
7
- end
8
-
9
- def child_classes_set
10
- @child_classes_set ||= Set.new
11
- end
12
-
13
- def child_classes
14
- child_classes_set.to_a
15
- end
16
- end
17
-
18
- def self.included(base)
19
- base.extend(ClassMethods)
20
- end
21
-
22
- end
23
- end
@@ -1,43 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- module ObjectTests
4
- class User < RedisObject
5
- use_store :global
6
- end
7
- class Thingy < RedisObject
8
-
9
- end
10
- class Doodad < RedisObject
11
-
12
- end
13
- end
14
-
15
- describe RedisObject do
16
-
17
- it "can reconnect to redis" do
18
- RedisObject.reconnect!
19
- RedisObject.store.reconnect!
20
- end
21
-
22
- it "can dump to a file" do
23
- obj = ObjectTests::User.create("test")
24
- RedisObject.dump_stores_to_files("/tmp")
25
- RedisObject.store.flushdb
26
- end
27
-
28
- it "can restore from a file" do
29
- RedisObject.restore_stores_from_files("/tmp")
30
- ObjectTests::User.find("test").should be_a(ObjectTests::User)
31
- end
32
-
33
- it "can get all stores" do
34
- RedisObject.stores.count.should eq(1)
35
- end
36
-
37
- it "can reset stores" do
38
- RedisObject.stores.each do |(name,store)|
39
- store.reset
40
- end
41
- end
42
-
43
- end
@@ -1,46 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- module BenchmarkSpec
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 BenchmarkedObject < RedisObject
19
-
20
- TestValues.keys.each do |type|
21
- send(type.to_sym,"a_#{type}".to_sym)
22
- end
23
-
24
- def aggregate
25
- sleep 0.1
26
- 42.7
27
- end
28
- benchmark :aggregate
29
-
30
- end
31
-
32
- describe Seabright::Benchmark do
33
- before do
34
- RedisObject.store.flushdb
35
- end
36
-
37
- it "benchmarks a call" do
38
-
39
- obj = BenchmarkedObject.create(TestData)
40
-
41
- obj.aggregate.should eq(42.7)
42
-
43
- end
44
-
45
- end
46
- end
@@ -1,144 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- module CollectionSpec
4
-
5
- class GrandDad < RedisObject; end
6
- class Daddy < RedisObject; end
7
- class Son < RedisObject; end
8
- class GrandSon < RedisObject; end
9
-
10
- describe Seabright::Collections do
11
- before do
12
-
13
- RedisObject.store.flushdb
14
- @granddad = GrandDad.create("gramps")
15
- @dad = Daddy.create("dad")
16
- @son = Son.create("sun")
17
- @sonny = Son.create("sonny")
18
- @grandson = GrandSon.create("baby")
19
- GrandDad << @dad
20
- @granddad << @dad
21
- @granddad << @son
22
- @dad << @son
23
- @dad.push @sonny
24
- @son.reference @grandson
25
-
26
- end
27
-
28
- it "can reference other objects" do
29
-
30
- @granddad.daddies.count.should eq(1)
31
- @granddad.sons.count.should eq(1)
32
- @dad.sons.count.should eq(2)
33
-
34
- end
35
-
36
- it "should have appropriate collections" do
37
-
38
- @granddad.has_collection?(:daddies).should eq(true)
39
- @granddad.has_collection?(:sons).should eq(true)
40
- @granddad.has_collection?(:grand_sons).should eq(false)
41
-
42
- end
43
-
44
- it "should cache collection accessors" do
45
-
46
- @granddad.daddies.should be_a(Seabright::Collection)
47
- @granddad.daddy.should be_a(Daddy)
48
-
49
- end
50
-
51
- it "should be able to iterate over collected items" do
52
-
53
- @dad.sons.count.should eq(2)
54
- @dad.sons.each do |s|
55
- s.should be_a(Son)
56
- end
57
-
58
- end
59
-
60
- it "can find items in a collection" do
61
-
62
- @dad = Daddy.find("dad")
63
- @dad.sons.find(son_id: "sonny").first.should be_a(Son)
64
-
65
- end
66
-
67
- it "can get one collection item" do
68
-
69
- @dad = Daddy.find("dad")
70
- @dad.son.should be_a(Son)
71
-
72
- end
73
-
74
- it "can get one collection item" do
75
-
76
- @dad = Daddy.find("dad")
77
- @dad.get(:son).should be_a(Son)
78
-
79
- end
80
-
81
- it "can get backreferences of a type" do
82
-
83
- @son.backreferences(GrandDad).each do |s|
84
- s.should be_a(GrandDad)
85
- end
86
-
87
- end
88
-
89
- it "can dereference itself" do
90
-
91
- @dad.dereference_from_backreferences
92
- GrandDad.find("gramps").daddies.count.should eq(0)
93
-
94
- end
95
-
96
- it "can delete items from a collection" do
97
-
98
- @dad.sons.delete(@sonny)
99
- @dad.sons.find(son_id: "sonny").first.should be_a(NilClass)
100
- @dad.sons.count.should eq(1)
101
-
102
- @dad.delete_child(@son)
103
- @dad.get(:sons).count.should eq(0)
104
-
105
- end
106
-
107
- it "can delete a collection" do
108
-
109
- @dad.sons.remove!
110
- @dad.collections.keys.should_not include(:sons)
111
- @son.remove_collection!(:grand_sons)
112
- @son.collections.keys.should_not include(:grand_sons)
113
-
114
- end
115
-
116
- it "retrieves via index" do
117
-
118
- 5.times do
119
- @dad << Son.create
120
- end
121
-
122
- # @dad.sons.indexed(:created_at,3,true).count.should eq(3)
123
-
124
- Son.indexed(:created_at,3,true).count.should eq(3)
125
-
126
- end
127
-
128
- it "can collect on classes themselves" do
129
-
130
- 5.times do
131
- Daddy << Son.create
132
- end
133
-
134
- Daddy.get(:sons).should be_a(Seabright::Collection)
135
- Daddy.get(:sons).count.should eq(5)
136
- Daddy.get(:son).should be_a(Son)
137
- Daddy.delete_child(Daddy.get(:son))
138
- Daddy.get(:sons).count.should eq(4)
139
- # Daddy.get(:sons).indexed(:created_at,3,true).count.should eq(3)
140
-
141
- end
142
-
143
- end
144
- end
@@ -1,56 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- module DefaultSpec
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
- # Delicious pizza!
19
- class DefaultedObject < RedisObject
20
-
21
- TestValues.keys.each do |type|
22
- send(type.to_sym,"a_#{type}".to_sym)
23
- end
24
- default_for :testy, "test"
25
- default_for :a_number, 42
26
-
27
- end
28
-
29
- describe Seabright::DefaultValues do
30
- before do
31
- RedisObject.store.flushdb
32
- end
33
-
34
- it "returns default value" do
35
-
36
- obj = DefaultedObject.create(TestData)
37
-
38
- obj.testy.should eq("test")
39
- obj.get(:a_number).should eq(27)
40
- obj.unset(:a_number)
41
- obj.get(:a_number).should eq(42)
42
-
43
- end
44
-
45
- it "returns default value after unset" do
46
-
47
- obj = DefaultedObject.create(TestData)
48
-
49
- obj.get(:a_number).should eq(27)
50
- obj.unset(:a_number)
51
- obj.get(:a_number).should eq(42)
52
-
53
- end
54
-
55
- end
56
- end
@@ -1,29 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- module FilterSpec
4
-
5
- class FilteredObject < RedisObject
6
-
7
- def double(k,v)
8
- (k == :testy) && v ? [:testy,v*2] : [k,v]
9
- end
10
- set_filter :double
11
-
12
- end
13
-
14
- describe Seabright::Filters do
15
- before do
16
- RedisObject.store.flushdb
17
- end
18
-
19
- it "modifies set and gets correctly" do
20
-
21
- obj = FilteredObject.create("test")
22
-
23
- obj.set(:testy,"test")
24
- obj.get(:testy).should eq("testtest")
25
-
26
- end
27
-
28
- end
29
- end
@@ -1,45 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- module IndexSpec
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
- # Delicious pizza!
19
- class IndexedObject < RedisObject
20
-
21
- TestValues.keys.each do |type|
22
- send(type.to_sym,"a_#{type}".to_sym)
23
- end
24
-
25
- sort_by :a_number
26
-
27
- end
28
-
29
- describe Seabright::Indices do
30
- before do
31
- RedisObject.store.flushdb
32
- end
33
-
34
- it "indexes on integer field" do
35
-
36
- 5.times do
37
- obj = IndexedObject.create(a_number: Random.rand(100))
38
- end
39
-
40
- IndexedObject.indexed(:a_number,3,true).count.should eq(3)
41
-
42
- end
43
-
44
- end
45
- end
@@ -1,96 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- module RenameClassSpec
4
- # Delicious pizza!
5
- class Pizza < RedisObject; end
6
- # We love toppings but our current name Topping is too ambiguous!
7
- class Topping < RedisObject; end
8
- # Let's change the class name to PizzaTopping!
9
- class PizzaTopping < RedisObject; end
10
-
11
- describe Seabright::Storage::Redis, "#rename_class" do
12
- before do
13
- RedisObject.store.flushdb
14
-
15
- mozzarella = Topping.create(:mozzarella)
16
- basil = Topping.create(:basil)
17
- tomato = Topping.create(:tomato)
18
- garlic = Topping.create(:garlic)
19
- oregano = Topping.create(:oregano)
20
- olive_oil = Topping.create(:olive_oil)
21
-
22
- marinara = Pizza.create(:marinara)
23
- [ tomato, garlic, oregano, olive_oil ].each{|topping| marinara << topping }
24
-
25
- margherita = Pizza.create(:margherita)
26
- [ tomato, mozzarella, basil, olive_oil ].each{|topping| margherita << topping }
27
- end
28
-
29
- it "setup works" do
30
- margherita = Pizza.find(:margherita)
31
- marinara = Pizza.find(:marinara)
32
- mozzarella = Topping.find(:mozzarella)
33
- basil = Topping.find(:basil)
34
- tomato = Topping.find(:tomato)
35
- garlic = Topping.find(:garlic)
36
- oregano = Topping.find(:oregano)
37
- olive_oil = Topping.find(:olive_oil)
38
-
39
- [ mozzarella, basil, tomato, garlic, oregano, olive_oil ].each do |topping|
40
- topping.get(:class).should == Topping.name
41
- topping.get(:key).should == "RenameClassSpec::Topping:#{topping.id}"
42
- topping.get(:topping_id).should == topping.id
43
- end
44
-
45
- Topping.indexed(:created_at).first.should_not be_nil
46
- Topping.indexed(:created_at).count.should == 5
47
-
48
- [margherita, marinara].each do |pizza|
49
- pizza.pizza_toppings.should be_nil
50
- pizza.toppings.count.should == 4
51
- pizza.toppings.should include(tomato.hkey)
52
- pizza.toppings.should include(olive_oil.hkey)
53
- end
54
-
55
- margherita.toppings.should include(basil.hkey)
56
- margherita.toppings.should include(mozzarella.hkey)
57
- marinara.toppings.should include(oregano.hkey)
58
- marinara.toppings.should include(garlic.hkey)
59
- end
60
-
61
- it "renames a class" do
62
- RedisObject.store.rename_class(:"RenameClassSpec::Topping", :"RenameClassSpec::PizzaTopping")
63
-
64
- margherita = Pizza.find(:margherita)
65
- marinara = Pizza.find(:marinara)
66
- mozzarella = PizzaTopping.find(:mozzarella)
67
- basil = PizzaTopping.find(:basil)
68
- tomato = PizzaTopping.find(:tomato)
69
- garlic = PizzaTopping.find(:garlic)
70
- oregano = PizzaTopping.find(:oregano)
71
- olive_oil = PizzaTopping.find(:olive_oil)
72
-
73
- [ mozzarella, basil, tomato, garlic, oregano, olive_oil ].each do |topping|
74
- topping.get(:class).should == PizzaTopping.name
75
- topping.get(:key).should == "RenameClassSpec::PizzaTopping:#{topping.id}"
76
- topping.get(:"renameclassspec::pizzatopping_id").should == topping.id
77
- # topping.get(:topping_id).should == nil
78
- end
79
-
80
- [margherita, marinara].each do |pizza|
81
- pizza.toppings.should be_nil
82
- pizza.pizza_toppings.count.should == 4
83
- pizza.pizza_toppings.should include(tomato.hkey)
84
- pizza.pizza_toppings.should include(olive_oil.hkey)
85
- end
86
-
87
- margherita.pizza_toppings.should include(basil.hkey)
88
- margherita.pizza_toppings.should include(mozzarella.hkey)
89
- marinara.pizza_toppings.should include(oregano.hkey)
90
- marinara.pizza_toppings.should include(garlic.hkey)
91
-
92
- PizzaTopping.indexed(:created_at).first.should_not be_nil
93
- PizzaTopping.indexed(:created_at).count.should == 5
94
- end
95
- end
96
- end