Class: NxtErrorRegistry::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/nxt_error_registry/registry.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry.



10
11
12
# File 'lib/nxt_error_registry/registry.rb', line 10

def initialize
  @store = { }
end

Instance Attribute Details

#storeObject (readonly)

Returns the value of attribute store.



14
15
16
# File 'lib/nxt_error_registry/registry.rb', line 14

def store
  @store
end

Class Method Details

.instanceObject



3
4
5
# File 'lib/nxt_error_registry/registry.rb', line 3

def self.instance
  @instance ||= send(:new)
end

Instance Method Details

#codesObject



23
24
25
# File 'lib/nxt_error_registry/registry.rb', line 23

def codes
  flat.map { |entry| entry.fetch(:code) }
end

#duplicated_codesObject



35
36
37
# File 'lib/nxt_error_registry/registry.rb', line 35

def duplicated_codes
  entries_by_codes.select { |_, v| v.size > 1 }
end

#entries_by_codesObject



27
28
29
30
31
32
33
# File 'lib/nxt_error_registry/registry.rb', line 27

def entries_by_codes
  flat.inject({}) do |acc, entry|
    code = entry.fetch(:code)
    (acc[code] ||= []) << entry
    acc
  end
end

#flatObject



19
20
21
# File 'lib/nxt_error_registry/registry.rb', line 19

def flat
  values.map(&:values).flatten
end