Sha256: fccb878b43a2d2f8aa1c0d7c80e466eb9c560dd14aba00241959534b9ff00b31

Contents?: true

Size: 914 Bytes

Versions: 3

Compression:

Stored size: 914 Bytes

Contents

# -*- encoding : utf-8 -*-
module RedisModelExtension
  module StoreKeys

    # store old arguments, need's to be called in find/get initialization
    # will remember old arguments and remember redis keys
    # if some fileds in redis key will change, then do rename
    # without this you can end up with old and new saved object!
    def store_keys
      store_redis_keys
    end

    private 

    # set old arguments
    def store_redis_keys
      args = to_arg
      #store main key
      redis_old_keys[:key] = self.class.generate_key(args) #store main key

      #store alias keys
      redis_old_keys[:aliases] = []
      redis_alias_config.each do |alias_name, fields|
        redis_old_keys[:aliases] << redis_alias_key(alias_name) if valid_alias_key? alias_name
      end
    end

    # get old arguments
    def redis_old_keys
      @redis_old_keys ||= {:key => nil, :aliases => []}
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
redis-model-extension-0.4.2 lib/redis-model-extension/store_keys.rb
redis-model-extension-0.4.1 lib/redis-model-extension/store_keys.rb
redis-model-extension-0.4.0 lib/redis-model-extension/store_keys.rb