From 9967eb9890c302b8a59e96881645e256f65ef3bb Mon Sep 17 00:00:00 2001 From: HassanAkbar Date: Mon, 23 Dec 2024 12:33:12 +0500 Subject: [PATCH] chore: unused code reverted --- lib/glossarist/collection.rb | 6 ++++ lib/glossarist/managed_concept_collection.rb | 32 +++++++++++++++----- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/lib/glossarist/collection.rb b/lib/glossarist/collection.rb index baced03..fd8517c 100644 --- a/lib/glossarist/collection.rb +++ b/lib/glossarist/collection.rb @@ -4,6 +4,12 @@ module Glossarist class Collection include Enumerable + # Path to concepts directory. + # @return [String] + attr_accessor :path + + # @param path [String] + # concepts directory path, either absolute or relative to CWD def initialize(path: nil) @path = path @index = {} diff --git a/lib/glossarist/managed_concept_collection.rb b/lib/glossarist/managed_concept_collection.rb index b1e0ae2..f891f05 100644 --- a/lib/glossarist/managed_concept_collection.rb +++ b/lib/glossarist/managed_concept_collection.rb @@ -1,15 +1,13 @@ module Glossarist - class ManagedConceptCollection < Lutaml::Model::Serializable + class ManagedConceptCollection include Enumerable - attribute :managed_concepts_ids, :hash, default: -> { {} } - attribute :managed_concepts, ManagedConcept, collection: true - attribute :concept_manager, ConceptManager, default: -> { ConceptManager.new } + attr_accessor :managed_concepts - yaml do - map :managed_concepts_ids, to: :managed_concepts_ids - map :managed_concepts, to: :managed_concepts - map :concept_manager, to: :concept_manager + def initialize + @managed_concepts = [] + @managed_concepts_ids = {} + @concept_manager = ConceptManager.new end def to_h @@ -22,15 +20,33 @@ def each(&block) @managed_concepts.each(&block) end + # Returns concept with given ID, if it is present in collection, or +nil+ + # otherwise. + # + # @param id [String] + # ManagedConcept ID + # @return [ManagedConcept, nil] def fetch(id) @managed_concepts.find { |c| c.uuid == id || c.uuid == @managed_concepts_ids[id] } end alias :[] :fetch + # If ManagedConcept with given ID is present in this collection, then + # returns it. Otherwise, instantiates a new ManagedConcept, adds it to + # the collection, and returns it. + # + # @param id [String] + # ManagedConcept ID + # @return [ManagedConcept] def fetch_or_initialize(id) fetch(id) or store(Config.class_for(:managed_concept).of_yaml(data: { id: id })) end + # 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_concepts << managed_concept