Module: Taskinator::Persistence::ClassMethods

Defined in:
lib/taskinator/persistence.rb

Instance Method Summary collapse

Instance Method Details

#base_keyObject

class must override this method to provide the base key to use for storing it’s instances, and it must be unique!



31
32
33
# File 'lib/taskinator/persistence.rb', line 31

def base_key
  @base_key ||= 'shared'
end

#fetch(uuid, instance_cache = {}) ⇒ Object

fetches the instance for given identifier optionally, provide a hash to use for the instance cache this argument is defaulted, so top level callers don’t need to provide this.



44
45
46
47
48
49
50
51
# File 'lib/taskinator/persistence.rb', line 44

def fetch(uuid, instance_cache={})
  key = key_for(uuid)
  if instance_cache.key?(key)
    instance_cache[key]
  else
    instance_cache[key] = RedisDeserializationVisitor.new(key, instance_cache).visit
  end
end

#key_for(uuid) ⇒ Object

returns the storage key for the given identifier



36
37
38
# File 'lib/taskinator/persistence.rb', line 36

def key_for(uuid)
  "taskinator:#{base_key}:#{uuid}"
end