lib/redis-model-extension.rb in redis-model-extension-0.3.7 vs lib/redis-model-extension.rb in redis-model-extension-0.3.8

- old
+ new

@@ -21,11 +21,11 @@ end module ClassMethods def initialize_redis_model_methods conf - @conf = conf + @conf = {:reject_nil_values => true}.merge(conf) #take all fields and make methods for them conf[:fields].each do |attr, action| define_method "#{attr}" do if self.args[attr] || self.args[attr] == false #== false is a fi for boolean variable self.args[attr].to_s.send(action) @@ -322,10 +322,11 @@ def save if valid? #generate key (possibly new) generated_key = redis_key RedisModelExtension::Database.redis.rename(self.class.generate_key(self.old_args), generated_key) if self.old_args && generated_key != self.class.generate_key(self.old_args) && RedisModelExtension::Database.redis.exists(self.class.generate_key(self.old_args)) - RedisModelExtension::Database.redis.hmset(generated_key, *self.args.reject{|k,v| v.nil?}.inject([]){ |arr,kv| arr + [kv[0], kv[1].to_s]}) + args = self.class.conf[:reject_nil_values] ? self.args.reject{|k,v| v.nil?} : self.args + RedisModelExtension::Database.redis.hmset(generated_key, *args.inject([]){ |arr,kv| arr + [kv[0], kv[1].to_s]}) #destroy aliases destroy_aliases! create_aliases #after save make new_key -> old_key \ No newline at end of file