Module: Taskinator::Persistence::ClassMethods
- Defined in:
- lib/taskinator/persistence.rb
Instance Method Summary collapse
-
#base_key ⇒ Object
class must override this method to provide the base key to use for storing it’s instances, and it must be unique!.
-
#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.
-
#key_for(uuid) ⇒ Object
returns the storage key for the given identifier.
-
#state_for(uuid) ⇒ Object
retrieves the workflow state for the given identifier this prevents to need to load the entire object when querying for the status of an instance.
Instance Method Details
#base_key ⇒ Object
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 raise NotImplementedError 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.
53 54 55 56 57 58 59 60 |
# File 'lib/taskinator/persistence.rb', line 53 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 |
#state_for(uuid) ⇒ Object
retrieves the workflow state for the given identifier this prevents to need to load the entire object when querying for the status of an instance
41 42 43 44 45 46 47 |
# File 'lib/taskinator/persistence.rb', line 41 def state_for(uuid) key = key_for(uuid) Taskinator.redis do |conn| state = conn.hget(key, :state) || 'initial' state.to_sym end end |