Class: Taskinator::Api::Processes

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/taskinator/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope = :shared) ⇒ Processes

Returns a new instance of Processes.



8
9
10
11
# File 'lib/taskinator/api.rb', line 8

def initialize(scope=:shared)
  @scope = scope
  @processes_list_key = Taskinator::Persistence.processes_list_key(scope)
end

Instance Attribute Details

#scopeObject (readonly)

Returns the value of attribute scope.



6
7
8
# File 'lib/taskinator/api.rb', line 6

def scope
  @scope
end

Instance Method Details

#each(&block) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/taskinator/api.rb', line 13

def each(&block)
  return to_enum(__method__) unless block_given?

  instance_cache = {}
  Taskinator.redis do |conn|
    uuids = conn.smembers(@processes_list_key)
    uuids.each do |uuid|
      yield Process.fetch(uuid, instance_cache)
    end
  end
end

#sizeObject



25
26
27
28
29
# File 'lib/taskinator/api.rb', line 25

def size
  Taskinator.redis do |conn|
    conn.scard(@processes_list_key)
  end
end