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!



29
30
31
# File 'lib/taskinator/persistence.rb', line 29

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.



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

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



34
35
36
# File 'lib/taskinator/persistence.rb', line 34

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