Class: Rworkflow::FlowRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/rworkflow/flow_registry.rb

Constant Summary collapse

REDIS_PREFIX =
'flow:__registry'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(prefix = nil) ⇒ FlowRegistry

Returns a new instance of FlowRegistry.



5
6
7
8
9
# 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

Instance Method Details

#add(flow) ⇒ Object



25
26
27
28
29
30
31
32
33
# 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 = {}) ⇒ Object

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



13
14
15
# File 'lib/rworkflow/flow_registry.rb', line 13

def all(options = {})
  return self.public_flows(options) + self.private_flows(options)
end

#include?(flow) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
49
# 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 = {}) ⇒ Object



21
22
23
# File 'lib/rworkflow/flow_registry.rb', line 21

def private_flows(options = {})
  return get(@private, **options)
end

#public_flows(options = {}) ⇒ Object



17
18
19
# File 'lib/rworkflow/flow_registry.rb', line 17

def public_flows(options = {})
  return get(@public, **options)
end

#remove(flow) ⇒ Object



35
36
37
38
39
40
41
# 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