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
24
# File 'lib/taskinator/api.rb', line 13

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

  identifiers = Taskinator.redis do |conn|
    conn.smembers(@processes_list_key)
  end

  instance_cache = {}
  identifiers.each do |identifier|
    yield Process.fetch(identifier, instance_cache)
  end
end

#sizeObject



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

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