Module: RedisRecord::Base
- Extended by:
- ActiveSupport::Concern
- Included in:
- RedisRecord
- Defined in:
- lib/redis_record/base.rb,
lib/redis_record/base/class_methods.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #destroy ⇒ Object (also: #destroy!)
- #key ⇒ Object
- #save ⇒ Object (also: #save!)
- #update_attributes(attrs) ⇒ Object
Instance Method Details
#destroy ⇒ Object Also known as: destroy!
24 25 26 27 28 29 30 31 32 |
# File 'lib/redis_record/base.rb', line 24 def destroy success = nil RedisRecord.REDIS.multi do run_callbacks :destroy do success = RedisRecord.REDIS.del key end end success.value == 1 ? self : nil end |
#key ⇒ Object
40 41 42 |
# File 'lib/redis_record/base.rb', line 40 def key self.class.key(id) end |
#save ⇒ Object Also known as: save!
13 14 15 16 17 18 19 20 21 |
# File 'lib/redis_record/base.rb', line 13 def save success = nil RedisRecord.REDIS.multi do run_callbacks :save do success = RedisRecord.REDIS.mapped_hmset(key, attributes) end end self.persisted = (success.value == "OK") end |
#update_attributes(attrs) ⇒ Object
35 36 37 38 |
# File 'lib/redis_record/base.rb', line 35 def update_attributes(attrs) assign_attributes attrs save end |