lib/ohm.rb in ohm-0.0.20 vs lib/ohm.rb in ohm-0.0.21

- old
+ new

@@ -457,11 +457,11 @@ def self.encode(value) Base64.encode64(value.to_s).gsub("\n", "") end def initialize(attrs = {}) - @_attributes = Hash.new {|hash,key| hash[key] = read_remote(key) } + @_attributes = Hash.new { |hash, key| hash[key] = read_remote(key) } update_attributes(attrs) end def new? !id @@ -472,21 +472,21 @@ initialize_id mutex do create_model_membership add_to_indices - save! + write end end def save return create if new? return unless valid? mutex do update_indices - save! + write end end def update(attrs) update_attributes(attrs) @@ -559,10 +559,15 @@ def key(*args) raise ModelIsNew if new? self.class.key(id, *args) end + def write + attributes.each { |att| write_remote(att, send(att)) } + self + end + private def self.db Ohm.redis end @@ -593,14 +598,9 @@ db.sadd(self.class.key(:all), id) end def delete_model_membership db.srem(self.class.key(:all), id) - end - - def save! - attributes.each { |att| write_remote(att, send(att)) } - self end def update_indices delete_from_indices add_to_indices