redis_object 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/.coveralls.yml +1 -0
  2. data/.gitignore +6 -0
  3. data/.travis.yml +5 -0
  4. data/Gemfile +8 -0
  5. data/README.markdown +179 -0
  6. data/Rakefile +10 -0
  7. data/lib/redis_object.rb +47 -0
  8. data/lib/redis_object/base.rb +408 -0
  9. data/lib/redis_object/collection.rb +388 -0
  10. data/lib/redis_object/defaults.rb +42 -0
  11. data/lib/redis_object/experimental/history.rb +49 -0
  12. data/lib/redis_object/ext/benchmark.rb +34 -0
  13. data/lib/redis_object/ext/cleaner.rb +14 -0
  14. data/lib/redis_object/ext/filters.rb +68 -0
  15. data/lib/redis_object/ext/script_cache.rb +92 -0
  16. data/lib/redis_object/ext/shardable.rb +18 -0
  17. data/lib/redis_object/ext/triggers.rb +101 -0
  18. data/lib/redis_object/ext/view_caching.rb +258 -0
  19. data/lib/redis_object/ext/views.rb +102 -0
  20. data/lib/redis_object/external_index.rb +25 -0
  21. data/lib/redis_object/indices.rb +97 -0
  22. data/lib/redis_object/inheritance_tracking.rb +23 -0
  23. data/lib/redis_object/keys.rb +37 -0
  24. data/lib/redis_object/storage.rb +93 -0
  25. data/lib/redis_object/storage/adapter.rb +46 -0
  26. data/lib/redis_object/storage/aws.rb +71 -0
  27. data/lib/redis_object/storage/mysql.rb +47 -0
  28. data/lib/redis_object/storage/redis.rb +119 -0
  29. data/lib/redis_object/timestamps.rb +74 -0
  30. data/lib/redis_object/tpl.rb +17 -0
  31. data/lib/redis_object/types.rb +276 -0
  32. data/lib/redis_object/validation.rb +89 -0
  33. data/lib/redis_object/version.rb +5 -0
  34. data/redis_object.gemspec +26 -0
  35. data/spec/adapter_spec.rb +43 -0
  36. data/spec/base_spec.rb +90 -0
  37. data/spec/benchmark_spec.rb +46 -0
  38. data/spec/collections_spec.rb +144 -0
  39. data/spec/defaults_spec.rb +56 -0
  40. data/spec/filters_spec.rb +29 -0
  41. data/spec/indices_spec.rb +45 -0
  42. data/spec/rename_class_spec.rb +96 -0
  43. data/spec/spec_helper.rb +38 -0
  44. data/spec/timestamp_spec.rb +28 -0
  45. data/spec/trigger_spec.rb +51 -0
  46. data/spec/types_spec.rb +103 -0
  47. data/spec/view_caching_spec.rb +130 -0
  48. data/spec/views_spec.rb +72 -0
  49. metadata +172 -0
@@ -0,0 +1,130 @@
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
@@ -0,0 +1,72 @@
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
metadata ADDED
@@ -0,0 +1,172 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redis_object
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - John Bragg
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: utf8_utils
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: redis
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: yajl-ruby
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: activesupport
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: ''
79
+ email:
80
+ - john@seabrightstudios.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .coveralls.yml
86
+ - .gitignore
87
+ - .travis.yml
88
+ - Gemfile
89
+ - README.markdown
90
+ - Rakefile
91
+ - lib/redis_object.rb
92
+ - lib/redis_object/base.rb
93
+ - lib/redis_object/collection.rb
94
+ - lib/redis_object/defaults.rb
95
+ - lib/redis_object/experimental/history.rb
96
+ - lib/redis_object/ext/benchmark.rb
97
+ - lib/redis_object/ext/cleaner.rb
98
+ - lib/redis_object/ext/filters.rb
99
+ - lib/redis_object/ext/script_cache.rb
100
+ - lib/redis_object/ext/shardable.rb
101
+ - lib/redis_object/ext/triggers.rb
102
+ - lib/redis_object/ext/view_caching.rb
103
+ - lib/redis_object/ext/views.rb
104
+ - lib/redis_object/external_index.rb
105
+ - lib/redis_object/indices.rb
106
+ - lib/redis_object/inheritance_tracking.rb
107
+ - lib/redis_object/keys.rb
108
+ - lib/redis_object/storage.rb
109
+ - lib/redis_object/storage/adapter.rb
110
+ - lib/redis_object/storage/aws.rb
111
+ - lib/redis_object/storage/mysql.rb
112
+ - lib/redis_object/storage/redis.rb
113
+ - lib/redis_object/timestamps.rb
114
+ - lib/redis_object/tpl.rb
115
+ - lib/redis_object/types.rb
116
+ - lib/redis_object/validation.rb
117
+ - lib/redis_object/version.rb
118
+ - redis_object.gemspec
119
+ - spec/adapter_spec.rb
120
+ - spec/base_spec.rb
121
+ - spec/benchmark_spec.rb
122
+ - spec/collections_spec.rb
123
+ - spec/defaults_spec.rb
124
+ - spec/filters_spec.rb
125
+ - spec/indices_spec.rb
126
+ - spec/rename_class_spec.rb
127
+ - spec/spec_helper.rb
128
+ - spec/timestamp_spec.rb
129
+ - spec/trigger_spec.rb
130
+ - spec/types_spec.rb
131
+ - spec/view_caching_spec.rb
132
+ - spec/views_spec.rb
133
+ homepage: ''
134
+ licenses: []
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ none: false
141
+ requirements:
142
+ - - ! '>='
143
+ - !ruby/object:Gem::Version
144
+ version: 1.9.2
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ none: false
147
+ requirements:
148
+ - - ! '>='
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubyforge_project: redis_object
153
+ rubygems_version: 1.8.23
154
+ signing_key:
155
+ specification_version: 3
156
+ summary: Maps arbitrary objects to a Redis store with indices and smart retrieval
157
+ and storage mechanisms.
158
+ test_files:
159
+ - spec/adapter_spec.rb
160
+ - spec/base_spec.rb
161
+ - spec/benchmark_spec.rb
162
+ - spec/collections_spec.rb
163
+ - spec/defaults_spec.rb
164
+ - spec/filters_spec.rb
165
+ - spec/indices_spec.rb
166
+ - spec/rename_class_spec.rb
167
+ - spec/spec_helper.rb
168
+ - spec/timestamp_spec.rb
169
+ - spec/trigger_spec.rb
170
+ - spec/types_spec.rb
171
+ - spec/view_caching_spec.rb
172
+ - spec/views_spec.rb