redpear 0.7.3 → 0.7.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/redpear/model.rb CHANGED
@@ -96,7 +96,7 @@ class Redpear::Model < Hash
96
96
  super()
97
97
  store 'id', (attrs.delete("id") || attrs.delete(:id) || self.class.pk_counter.next).to_s
98
98
  update(attrs)
99
- self.class.members.add(id)
99
+ after_create(attrs)
100
100
  end
101
101
 
102
102
  # @return [String] the ID of this record
@@ -179,14 +179,12 @@ class Redpear::Model < Hash
179
179
  # @return [Hash]
180
180
  def update(hash)
181
181
  clear
182
- self.class.transaction do
183
- bulk = {}
184
- hash.each do |name, value|
185
- column = self.class.columns[name] || next
186
- store_attribute bulk, column, value
187
- end
188
- attributes.merge! bulk
182
+ bulk = {}
183
+ hash.each do |name, value|
184
+ column = self.class.columns[name] || next
185
+ store_attribute bulk, column, value
189
186
  end
187
+ attributes.merge! bulk
190
188
  self
191
189
  end
192
190
 
@@ -214,10 +212,11 @@ class Redpear::Model < Hash
214
212
  # Destroy the record.
215
213
  # @return [Boolean] true if successful
216
214
  def destroy
217
- lookups # Build before transaction
215
+ before_destroy
218
216
  self.class.transaction do
219
217
  lookups.each {|l| l.delete(id) }
220
218
  attributes.purge!
219
+ after_destroy
221
220
  end
222
221
  freeze
223
222
  end
@@ -249,7 +248,27 @@ class Redpear::Model < Hash
249
248
 
250
249
  value
251
250
  end
252
- protected :store, :store_attribute
251
+
252
+ # Cheap after create callback, override in subclasses and don't forget to
253
+ # call `super()`.
254
+ # @params [Hash] attrs attributes used on initialization
255
+ def after_create(attrs)
256
+ self.class.members.add(id)
257
+ end
258
+
259
+ # Cheap before destroy callback, override in subclasses and don't forget to
260
+ # call `super()`.
261
+ def before_destroy
262
+ lookups # Build lookups
263
+ end
264
+
265
+ # Cheap after destroy callback, override in subclasses and don't forget to
266
+ # call `super()`. Called within the transaction, be careful not to include
267
+ # read opertions.
268
+ def after_destroy
269
+ end
270
+
271
+ protected :store, :store_attribute, :after_create, :before_destroy, :after_destroy
253
272
  private :fetch, :delete, :delete_if, :keep_if, :merge!, :reject!, :select!, :replace
254
273
 
255
274
  end
@@ -108,7 +108,7 @@ class Redpear::Store::Hash < Redpear::Store::Enumerable
108
108
  hash = hash.reject do |field, value|
109
109
  delete(field) if value.nil?
110
110
  end
111
- conn.hmset key, *hash.flatten
111
+ conn.hmset key, *hash.flatten unless hash.empty?
112
112
  end
113
113
 
114
114
  # Comparator
@@ -2,7 +2,7 @@ module Redpear
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 7
5
- TINY = 3
5
+ TINY = 4
6
6
  PRE = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redpear
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.3
4
+ version: 0.7.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-28 00:00:00.000000000 Z
12
+ date: 2012-04-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis
16
- requirement: &10021500 !ruby/object:Gem::Requirement
16
+ requirement: &13791300 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.2.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *10021500
24
+ version_requirements: *13791300
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &10018400 !ruby/object:Gem::Requirement
27
+ requirement: &13790900 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *10018400
35
+ version_requirements: *13790900
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &10032440 !ruby/object:Gem::Requirement
38
+ requirement: &13807720 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *10032440
46
+ version_requirements: *13807720
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &10031460 !ruby/object:Gem::Requirement
49
+ requirement: &13807020 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *10031460
57
+ version_requirements: *13807020
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: shoulda-matchers
60
- requirement: &10030280 !ruby/object:Gem::Requirement
60
+ requirement: &13806580 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *10030280
68
+ version_requirements: *13806580
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: machinist
71
- requirement: &10029100 !ruby/object:Gem::Requirement
71
+ requirement: &13806160 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *10029100
79
+ version_requirements: *13806160
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: factory_girl
82
- requirement: &10027760 !ruby/object:Gem::Requirement
82
+ requirement: &13805500 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *10027760
90
+ version_requirements: *13805500
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: hiredis
93
- requirement: &10026860 !ruby/object:Gem::Requirement
93
+ requirement: &13804860 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,7 +98,7 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *10026860
101
+ version_requirements: *13804860
102
102
  description: Simple, elegant & efficient ORM for Redis
103
103
  email: dimitrij@blacksquaremedia.com
104
104
  executables: []