Sha256: a4564d95bf9cd9f7209c0646855328018d10ea601b1aade6388c380a47eb3919
Contents?: true
Size: 884 Bytes
Versions: 9
Compression:
Stored size: 884 Bytes
Contents
# frozen_string_literal: true # rubocop:todo all module Unified class EntityMap extend Forwardable def initialize @map = {} end def set(type, id, value) @map[type] ||= {} if @map[type][id] raise Error::EntityMapOverwriteAttempt, "Cannot set #{type} #{id} because it is already defined" end @map[type][id] = value end def get(type, id) unless @map[type] raise Error::EntityMissing, "There are no #{type} entities known" end unless v = @map[type][id] raise Error::EntityMissing, "There is no #{type} #{id} known" end v end def get_any(id) @map.each do |type, sub| if sub[id] return sub[id] end end raise Error::EntityMissing, "There is no #{id} known" end def_delegators :@map, :[], :fetch end end
Version data entries
9 entries across 9 versions & 2 rubygems