Class: Perfgate::Workloads::Registry

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/perfgate/workloads/registry.rb

Overview

Collects Workload instances discovered for a run and enforces the uniqueness rule from spec section 9.2: "a duplicate explicit ID is a configuration error".

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry.



21
22
23
# File 'lib/perfgate/workloads/registry.rb', line 21

def initialize
  @workloads = {}
end

Class Method Details

.instanceObject



12
13
14
# File 'lib/perfgate/workloads/registry.rb', line 12

def instance
  @instance ||= new
end

.reset!Object



16
17
18
# File 'lib/perfgate/workloads/registry.rb', line 16

def reset!
  @instance = new
end

Instance Method Details

#[](id) ⇒ Object



31
32
33
# File 'lib/perfgate/workloads/registry.rb', line 31

def [](id)
  @workloads[id]
end

#clearObject



45
46
47
# File 'lib/perfgate/workloads/registry.rb', line 45

def clear
  @workloads.clear
end

#each(&block) ⇒ Object



35
36
37
38
39
# File 'lib/perfgate/workloads/registry.rb', line 35

def each(&block)
  return enum_for(:each) unless block

  @workloads.each_value(&block)
end

#idsObject



41
42
43
# File 'lib/perfgate/workloads/registry.rb', line 41

def ids
  @workloads.keys
end

#register(workload) ⇒ Object



25
26
27
28
29
# File 'lib/perfgate/workloads/registry.rb', line 25

def register(workload)
  raise Perfgate::WorkloadError, "duplicate workload id: #{workload.id.inspect}" if @workloads.key?(workload.id)

  @workloads[workload.id] = workload
end