Skip to content

Commit

Permalink
chore: unused code reverted
Browse files Browse the repository at this point in the history
  • Loading branch information
HassanAkbar committed Dec 23, 2024
1 parent 624a059 commit 9967eb9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
6 changes: 6 additions & 0 deletions lib/glossarist/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down
32 changes: 24 additions & 8 deletions lib/glossarist/managed_concept_collection.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down

0 comments on commit 9967eb9

Please sign in to comment.