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!
17 18 19 |
# File 'lib/taskinator/persistence.rb', line 17 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.
41 42 43 44 45 46 47 48 |
# File 'lib/taskinator/persistence.rb', line 41 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
22 23 24 |
# File 'lib/taskinator/persistence.rb', line 22 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
29 30 31 32 33 34 35 |
# File 'lib/taskinator/persistence.rb', line 29 def state_for(uuid) key = key_for(uuid) Taskinator.redis do |conn| state = conn.hget(key, :state) || 'initial' state.to_sym end end |