active_redis_orm 0.0.3 → 0.0.4

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: dee8484ce398189d1fe063d40a2e885f981fbda3
4
- data.tar.gz: 9d924067aa9f3a298986883c108fee866b035de2
3
+ metadata.gz: cc835df89e4be39ac1b69d89ab593d5ce757456f
4
+ data.tar.gz: 254047a9457bd3046c12222df4758f80127b2cc1
5
5
  SHA512:
6
- metadata.gz: 347322720474ed9faaaeb1da27a2a1f93ec45a410918a01287ca77078d207bff33869133ce8805609f465f2f173a5ae55bfd7e3149f7479634c24cd842507c7d
7
- data.tar.gz: e4e79c3c5369885c332c5ace88d4e3f97b1d48b67d54d31309f6491d57f322043d8fabcc65fec65dbe6052463b2a3f7e04bd7332d7ca187984ff0c1a1a050baa
6
+ metadata.gz: 6c803373333f64291d1574ffc25ed5728635ad50d371b2c60e71cdd8922bd669e6e0f59e6cdffae2f60e3885ffc8bfdbce03ae22d29653b5b21d546cd93a5add
7
+ data.tar.gz: c478976912aad60b089831533e9c87a694e684e1b735a33faad9de3bedde4c905aae67ab267afca5feabd7c77b75f73a80293a4edec5976a81f2a04c7fe4de3f
@@ -98,11 +98,17 @@ module ActiveRedis
98
98
 
99
99
  def #{field_name}=(value)
100
100
  #{field_name}_will_change!
101
+ value = ActiveRedis::NilObject.new if value.nil?
101
102
  @attributes[:#{field_name}] = value
102
103
  end
103
104
 
104
105
  def set_#{field_name}(value)
105
- #{field_name}_object.value = value.last
106
+ val = value.last
107
+ if val.nil?
108
+ destroy_#{field_name}
109
+ else
110
+ #{field_name}_object.value = val
111
+ end
106
112
  after_set(:#{field_name})
107
113
  end
108
114
  }
@@ -123,11 +129,20 @@ module ActiveRedis
123
129
 
124
130
  def #{field_name}=(value)
125
131
  #{field_name}_will_change!
126
- @attributes[:#{field_name}] = value.to_i
132
+ if value.nil?
133
+ @attributes[:#{field_name}] = ActiveRedis::NilObject.new
134
+ else
135
+ @attributes[:#{field_name}] = value.to_i
136
+ end
127
137
  end
128
138
 
129
139
  def set_#{field_name}(value)
130
- #{field_name}_object.value = value.last.to_i
140
+ val = value.last
141
+ if val.nil?
142
+ destroy_#{field_name}
143
+ else
144
+ #{field_name}_object.value = val.to_i
145
+ end
131
146
  after_set(:#{field_name})
132
147
  end
133
148
  }
@@ -148,11 +163,20 @@ module ActiveRedis
148
163
 
149
164
  def #{field_name}=(value)
150
165
  #{field_name}_will_change!
151
- @attributes[:#{field_name}] = value.to_f
166
+ if value.nil?
167
+ @attributes[:#{field_name}] = ActiveRedis::NilObject.new
168
+ else
169
+ @attributes[:#{field_name}] = value.to_f
170
+ end
152
171
  end
153
172
 
154
173
  def set_#{field_name}(value)
155
- #{field_name}_object.value = value.last.to_f
174
+ val = value.last
175
+ if val.nil?
176
+ destroy_#{field_name}
177
+ else
178
+ #{field_name}_object.value = val.to_f
179
+ end
156
180
  after_set(:#{field_name})
157
181
  end
158
182
  }
@@ -319,10 +343,10 @@ module ActiveRedis
319
343
  def set_#{field_name}(value)
320
344
  changes = value.first.last
321
345
  changes[:additions].each do |addition|
322
- #{field_name}_object[changes[:hash].key(addition)] = addition
346
+ self.#{field_name}_object[addition] = changes[:hash].key(addition)
323
347
  end
324
348
  changes[:drops].each do |drop|
325
- #{field_name}_object.delete(drop)
349
+ self.#{field_name}_object.delete(drop)
326
350
  end
327
351
  after_set(:#{field_name})
328
352
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveRedis
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -11,6 +11,7 @@ require "active_redis/dirty_objects/hash"
11
11
  require "active_redis/dirty_objects/sorted_set"
12
12
  require "active_redis/all_list"
13
13
  require "active_redis/timestamps"
14
+ require "active_redis/nil_object"
14
15
 
15
16
  module ActiveRedis
16
17
  mattr_accessor :redis
@@ -148,6 +148,25 @@ describe ActiveRedis do
148
148
  object.hash.should == {"foo" => "bar"}
149
149
  end
150
150
 
151
+ it "saves sorted sets correctly" do
152
+ object = ActiveRedisObject.new
153
+ object.sorted_set["goofy"] = 2
154
+ object.sorted_set["hola"] = 1
155
+ object.save
156
+ object.reload!
157
+ object.sorted_set.should == ["hola", "goofy"]
158
+ end
159
+
160
+ it "removes the field if it's set to nil" do
161
+ object = ActiveRedisObject.new
162
+ object.foo = "foo"
163
+ object.save
164
+ object.foo = nil
165
+ object.save
166
+ object.reload!
167
+ object.foo.should == nil
168
+ end
169
+
151
170
  it "tracks changes well" do
152
171
  object = ActiveRedisObject.new
153
172
  object.hash = {}
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.3
4
+ version: 0.0.4
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-07-14 00:00:00.000000000 Z
11
+ date: 2014-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler