lib/glossarist/managed_concept_collection.rb in glossarist-1.1.0 vs lib/glossarist/managed_concept_collection.rb in glossarist-2.0.0
- old
+ new
@@ -4,10 +4,11 @@
class ManagedConceptCollection
include Enumerable
def initialize
@managed_concepts = {}
+ @managed_concepts_ids = {}
@concept_manager = ConceptManager.new
end
# @return [Array<ManagedConcept>]
def managed_concepts
@@ -37,11 +38,11 @@
#
# @param id [String]
# ManagedConcept ID
# @return [ManagedConcept, nil]
def fetch(id)
- @managed_concepts[id]
+ @managed_concepts[id] || @managed_concepts[@managed_concepts_ids[id]]
end
alias :[] :fetch
# If ManagedConcept with given ID is present in this collection, then
@@ -50,19 +51,20 @@
#
# @param id [String]
# ManagedConcept ID
# @return [ManagedConcept]
def fetch_or_initialize(id)
- fetch(id) or store(ManagedConcept.new(id: id))
+ fetch(id) or store(ManagedConcept.new(data: { id: id }))
end
- # Adds concept to the collection. If collection contains a concept with
+ # Adds concept to the collection. If collection contains a concept with
# the same ID already, that concept is replaced.
#
# @param managed_concept [ManagedConcept]
# ManagedConcept about to be added
def store(managed_concept)
- @managed_concepts[managed_concept.id] = managed_concept
+ @managed_concepts[managed_concept.uuid] = managed_concept
+ @managed_concepts_ids[managed_concept.id] = managed_concept.uuid if managed_concept.id
end
alias :<< :store
def load_from_files(path)