Module: RedisColumn::Record::InstanceMethods
- Defined in:
- lib/redis-column.rb
Instance Method Summary collapse
-
#assign_redis_columns ⇒ Object
Assigns the values from Redis unless already specified.
-
#delete_redis_attribute(column_name) ⇒ Object
Delete value from Redis.
-
#delete_redis_columns! ⇒ Object
Delete all values in Redis.
-
#read_redis_attribute(column_name) ⇒ Object
Read from Redis and unserialise.
-
#redis_key(column_name) ⇒ Object
Returns the key to be used in Redis.
-
#save_redis_columns! ⇒ Object
Save all values back to Redis.
-
#write_redis_attribute(column_name, val) ⇒ Object
Serialise and write to Redis.
Instance Method Details
#assign_redis_columns ⇒ Object
Assigns the values from Redis unless already specified
77 78 79 80 81 |
# File 'lib/redis-column.rb', line 77 def assign_redis_columns redis_columns.each do |column_name| write_attribute column_name, read_redis_attribute(column_name) unless read_attribute(column_name.to_s).present? end end |
#delete_redis_attribute(column_name) ⇒ Object
Delete value from Redis
72 73 74 |
# File 'lib/redis-column.rb', line 72 def delete_redis_attribute column_name redis_instance.del(redis_key(column_name)) end |
#delete_redis_columns! ⇒ Object
Delete all values in Redis
91 92 93 94 95 |
# File 'lib/redis-column.rb', line 91 def delete_redis_columns! redis_columns.each do |column_name| delete_redis_attribute column_name end end |
#read_redis_attribute(column_name) ⇒ Object
Read from Redis and unserialise
61 62 63 64 |
# File 'lib/redis-column.rb', line 61 def read_redis_attribute column_name val = redis_instance.get(redis_key(column_name)) YAML.load(val) unless val.nil? end |
#redis_key(column_name) ⇒ Object
Returns the key to be used in Redis
56 57 58 |
# File 'lib/redis-column.rb', line 56 def redis_key column_name "#{self.class.model_name.i18n_key}:#{self.id}:#{column_name}" end |
#save_redis_columns! ⇒ Object
Save all values back to Redis
84 85 86 87 88 |
# File 'lib/redis-column.rb', line 84 def save_redis_columns! redis_columns.each do |column_name| write_redis_attribute column_name, read_attribute(column_name) end end |
#write_redis_attribute(column_name, val) ⇒ Object
Serialise and write to Redis
67 68 69 |
# File 'lib/redis-column.rb', line 67 def write_redis_attribute column_name, val redis_instance.set(redis_key(column_name), val.to_yaml) and return val end |