Sha256: f480c9768c23231a3298e37c48fda1b73795c989dbca57cbf7f835f764d1b019

Contents?: true

Size: 739 Bytes

Versions: 1

Compression:

Stored size: 739 Bytes

Contents

module NxtErrorRegistry
  class Registry
    def self.instance
      @instance ||= send(:new)
    end

    # Usually we don't want this to be initialized other than through instance
    private_class_method :new

    def initialize
      @store = {}
    end

    attr_reader :store

    delegate_missing_to :store
    delegate :to_s, :inspect, to: :store

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

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

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nxt_error_registry-0.3.0 lib/nxt_error_registry/registry.rb