class Rworkflow::FlowRegistry
Constants
- REDIS_PREFIX
Public Class Methods
new(prefix = nil)
click to toggle source
# File lib/rworkflow/flow_registry.rb, line 5 def initialize(prefix = nil) @redis_key = [REDIS_PREFIX, prefix].compact.join(':') @public = RedisRds::SortedSet.new("#{@redis_key}:public") @private = RedisRds::SortedSet.new("#{@redis_key}:private") end
Public Instance Methods
add(flow)
click to toggle source
# File lib/rworkflow/flow_registry.rb, line 25 def add(flow) key = flow.created_at.to_i if flow.public? @public.add(key, flow.id) else @private.add(key, flow.id) end end
all(options = {})
click to toggle source
Warning: using parent_class forces us to load everything, make this potentially much slower as we have to do the pagination in the app, not in the db
# File lib/rworkflow/flow_registry.rb, line 13 def all(options = {}) return self.public_flows(options) + self.private_flows(options) end
include?(flow)
click to toggle source
# File lib/rworkflow/flow_registry.rb, line 43 def include?(flow) if flow.public? @public.include?(flow.id) else @private.include?(flow.id) end end
private_flows(options = {})
click to toggle source
# File lib/rworkflow/flow_registry.rb, line 21 def private_flows(options = {}) return get(@private, **options) end
public_flows(options = {})
click to toggle source
# File lib/rworkflow/flow_registry.rb, line 17 def public_flows(options = {}) return get(@public, **options) end
remove(flow)
click to toggle source
# File lib/rworkflow/flow_registry.rb, line 35 def remove(flow) if flow.public? @public.remove(flow.id) else @private.remove(flow.id) end end
Private Instance Methods
get(zset, parent_class: nil, from: nil, to: nil, order: :asc)
click to toggle source
# File lib/rworkflow/flow_registry.rb, line 51 def get(zset, parent_class: nil, from: nil, to: nil, order: :asc) from = from.to_i to = to.nil? ? -1 : to.to_i ids = [] if parent_class.nil? || parent_class == Flow ids = zset.range(from, to, order: order) else ids = zset.range(0, -1, order: order).select do |id| klass = Flow.read_flow_class(id) !klass.nil? && klass <= parent_class end.slice(from..to) end return ids end