active_redis_orm 0.0.7 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c05be7c5fafe7f5194a6dfe7d3662cc05173a3e0
4
- data.tar.gz: 9b33a859fb406fa9ae081b9fe02ed63198a3b0e6
3
+ metadata.gz: 8b411bfb8f667027da1b252715b2558fb963a2a8
4
+ data.tar.gz: 55692c9536d1fbeb6be3ed325785f487f2c97c16
5
5
  SHA512:
6
- metadata.gz: 707db972bd38d28f098babdfc36dadd05a2be22bb707a607ed9789d3b45c121f7894e4dc391ed3f3d78722b93b944b14dde4e45334486a79771d0040459e0c58
7
- data.tar.gz: 446768c2dcebcde98d8356902ff0db0a6c97a329ed6873adb9bfa11a4f713aaadba98cd3ddcb1d5bcb13e2a125451a443c8c7e539d2f5f12faac78225bda7c60
6
+ metadata.gz: e22e86f443f986590ab0e9bc155d8d9c0d414fb0c1f958f3fe4440ede5141b18f09d44fc4dacba6fd34b8d2f7a48ef8d472a861b7555dbe4acda9e02e796ac59
7
+ data.tar.gz: 29fc748ea40c80f9f2f0d792fcbec6ba408d7a730bce41239159aa6df172134ed92a133a53959af7ac44e784599eaf2a635c133386ceb617502ad9b86a2129ff
@@ -39,8 +39,8 @@ module ActiveRedis
39
39
  end
40
40
 
41
41
  def define_field(field_name, options)
42
- define_attribute_methods field_name
43
- class_eval %Q{
42
+ define_attribute_method field_name
43
+ attributes_module.module_eval %Q{
44
44
  def #{field_name}_redis_key
45
45
  "#{self.redis_namespace}:\#{id}:#{field_name}"
46
46
  end
@@ -88,12 +88,12 @@ module ActiveRedis
88
88
  end
89
89
 
90
90
  def string_field(field_name, options)
91
- class_eval %Q{
91
+ attributes_module.module_eval %Q{
92
92
  def #{field_name}_object
93
93
  Redis::Value.new(#{field_name}_redis_key)
94
94
  end
95
95
 
96
- def #{field_name}
96
+ def #{field_name}_val
97
97
  @attributes[:#{field_name}] ||= begin
98
98
  value = #{field_name}_object.value
99
99
  value.nil? ? value : value.to_s
@@ -119,12 +119,12 @@ module ActiveRedis
119
119
  end
120
120
 
121
121
  def integer_field(field_name, options)
122
- class_eval %Q{
122
+ attributes_module.module_eval %Q{
123
123
  def #{field_name}_object
124
124
  Redis::Value.new(#{field_name}_redis_key)
125
125
  end
126
126
 
127
- def #{field_name}
127
+ def #{field_name}_val
128
128
  @attributes[:#{field_name}] ||= begin
129
129
  value = #{field_name}_object.value
130
130
  value.nil? ? value : value.to_i
@@ -153,12 +153,12 @@ module ActiveRedis
153
153
  end
154
154
 
155
155
  def float_field(field_name, options)
156
- class_eval %Q{
156
+ attributes_module.module_eval %Q{
157
157
  def #{field_name}_object
158
158
  Redis::Value.new(#{field_name}_redis_key)
159
159
  end
160
160
 
161
- def #{field_name}
161
+ def #{field_name}_val
162
162
  @attributes[:#{field_name}] ||= begin
163
163
  value = #{field_name}_object.value
164
164
  value.nil? ? value : value.to_f
@@ -187,12 +187,12 @@ module ActiveRedis
187
187
  end
188
188
 
189
189
  def boolean_field(field_name, options)
190
- class_eval %Q{
190
+ attributes_module.module_eval %Q{
191
191
  def #{field_name}_object
192
192
  Redis::Value.new(#{field_name}_redis_key)
193
193
  end
194
194
 
195
- def #{field_name}
195
+ def #{field_name}_val
196
196
  return @attributes[:#{field_name}] if @attributes[:#{field_name}].boolean?
197
197
  @attributes[:#{field_name}] ||= begin
198
198
  value = #{field_name}_object.value
@@ -224,12 +224,12 @@ module ActiveRedis
224
224
  end
225
225
 
226
226
  def counter_field(field_name, options)
227
- class_eval %Q{
227
+ attributes_module.module_eval %Q{
228
228
  def #{field_name}_object
229
229
  Redis::Counter.new(#{field_name}_redis_key)
230
230
  end
231
231
 
232
- def #{field_name}
232
+ def #{field_name}_val
233
233
  @attributes[:#{field_name}] ||= #{field_name}_object.value.to_i
234
234
  end
235
235
 
@@ -254,12 +254,12 @@ module ActiveRedis
254
254
  end
255
255
 
256
256
  def list_field(field_name, options)
257
- class_eval %Q{
257
+ attributes_module.module_eval %Q{
258
258
  def #{field_name}_object
259
259
  Redis::List.new(#{field_name}_redis_key)
260
260
  end
261
261
 
262
- def #{field_name}
262
+ def #{field_name}_val
263
263
  @attributes[:#{field_name}] ||= begin
264
264
  ActiveRedis::DirtyObjects::Array.new(#{field_name}_object.values)
265
265
  end
@@ -296,12 +296,12 @@ module ActiveRedis
296
296
  end
297
297
 
298
298
  def set_field(field_name, options)
299
- class_eval %Q{
299
+ attributes_module.module_eval %Q{
300
300
  def #{field_name}_object
301
301
  Redis::Set.new(#{field_name}_redis_key)
302
302
  end
303
303
 
304
- def #{field_name}
304
+ def #{field_name}_val
305
305
  @attributes[:#{field_name}] ||= begin
306
306
  ActiveRedis::DirtyObjects::Array.new(#{field_name}_object.members)
307
307
  end
@@ -329,12 +329,12 @@ module ActiveRedis
329
329
  end
330
330
 
331
331
  def sorted_set_field(field_name, options)
332
- class_eval %Q{
332
+ attributes_module.module_eval %Q{
333
333
  def #{field_name}_object
334
334
  Redis::SortedSet.new(#{field_name}_redis_key)
335
335
  end
336
336
 
337
- def #{field_name}
337
+ def #{field_name}_val
338
338
  @attributes[:#{field_name}] ||= begin
339
339
  ActiveRedis::DirtyObjects::SortedSet.new(#{field_name}_object.members)
340
340
  end
@@ -358,12 +358,12 @@ module ActiveRedis
358
358
  end
359
359
 
360
360
  def hash_field(field_name, options)
361
- class_eval %Q{
361
+ attributes_module.module_eval %Q{
362
362
  def #{field_name}_hash_set
363
363
  Redis::HashKey.new(#{field_name}_redis_key)
364
364
  end
365
365
 
366
- def #{field_name}
366
+ def #{field_name}_val
367
367
  @attributes[:#{field_name}] ||= begin
368
368
  ActiveRedis::DirtyObjects::Hash[#{field_name}_hash_set.all]
369
369
  end
@@ -388,8 +388,8 @@ module ActiveRedis
388
388
 
389
389
  def date_field(field_name, options)
390
390
  string_field(field_name, options)
391
- class_eval %Q{
392
- def #{field_name}
391
+ attributes_module.module_eval %Q{
392
+ def #{field_name}_val
393
393
  @attributes[:#{field_name}] ||= begin
394
394
  value = #{field_name}_object.value
395
395
  if value.blank?
@@ -416,8 +416,8 @@ module ActiveRedis
416
416
 
417
417
  def time_field(field_name, options)
418
418
  string_field(field_name, options)
419
- class_eval %Q{
420
- def #{field_name}
419
+ attributes_module.module_eval %Q{
420
+ def #{field_name}_val
421
421
  @attributes[:#{field_name}] ||= begin
422
422
  value = #{field_name}_object.value
423
423
  if value.blank?
@@ -7,5 +7,17 @@ module ActiveRedis
7
7
  def present?
8
8
  false
9
9
  end
10
+
11
+ def inspect
12
+ "nil"
13
+ end
14
+
15
+ def as_json(*args)
16
+ nil
17
+ end
18
+
19
+ def to_s
20
+ ""
21
+ end
10
22
  end
11
23
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveRedis
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -67,9 +67,13 @@ module ActiveRedis
67
67
  end
68
68
  end
69
69
 
70
+ def attribute(name)
71
+ public_send("#{name}_val")
72
+ end
73
+
70
74
  class << self
71
75
  include ActiveRedis::Attributes
72
- attr_accessor :attribute_definitions
76
+ attr_accessor :attribute_definitions, :attributes_module
73
77
 
74
78
  def find(id)
75
79
  new(id)
@@ -116,6 +120,8 @@ module ActiveRedis
116
120
  end
117
121
  end
118
122
  end
123
+ klass.attributes_module = Module.new
124
+ klass.send(:include, klass.attributes_module)
119
125
  end
120
126
  end
121
127
  end
@@ -0,0 +1,7 @@
1
+ require "active_redis_orm"
2
+
3
+ describe ActiveRedis::NilObject do
4
+ it "acts as nil when serialized" do
5
+ {foo: ActiveRedis::NilObject.new}.to_json.should == '{"foo":null}'
6
+ end
7
+ end
@@ -334,4 +334,19 @@ describe ActiveRedis do
334
334
  end
335
335
  end
336
336
 
337
+ context "super" do
338
+ class ARWithSuper < ActiveRedis::Base
339
+ field :wagamama
340
+
341
+ def wagamama
342
+ "#{super}!"
343
+ end
344
+ end
345
+
346
+ it "allows super to be called on attribute definitions" do
347
+ object = ARWithSuper.create(wagamama: "bar")
348
+ object.wagamama.should == "bar!"
349
+ end
350
+ end
351
+
337
352
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_redis_orm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Caspy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-28 00:00:00.000000000 Z
11
+ date: 2014-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -134,6 +134,7 @@ files:
134
134
  - lib/active_redis/timestamps.rb
135
135
  - lib/active_redis/version.rb
136
136
  - lib/active_redis_orm.rb
137
+ - spec/lib/active_redis/nil_object_spec.rb
137
138
  - spec/lib/active_redis/validation_spec.rb
138
139
  - spec/lib/active_redis_spec.rb
139
140
  - spec/lib/attributes_spec.rb
@@ -162,6 +163,7 @@ signing_key:
162
163
  specification_version: 4
163
164
  summary: ActiveRedis is an ORM for redis written in Ruby.
164
165
  test_files:
166
+ - spec/lib/active_redis/nil_object_spec.rb
165
167
  - spec/lib/active_redis/validation_spec.rb
166
168
  - spec/lib/active_redis_spec.rb
167
169
  - spec/lib/attributes_spec.rb