Skip to content

Commit

Permalink
making managed_concept configureable (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
HassanAkbar authored Feb 29, 2024
1 parent 2b8f94d commit 825430d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/glossarist/concept_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def load_concept_from_file(filename)
concept_hash = Psych.safe_load(File.read(filename), permitted_classes: [Date, Time])
concept_hash["uuid"] = concept_hash["id"] || File.basename(filename, ".*")

concept = ManagedConcept.new(concept_hash)
concept = Config.class_for(:managed_concept).new(concept_hash)
concept.localized_concepts.each do |_lang, id|
localized_concept = load_localized_concept(id)
concept.add_l10n(localized_concept)
Expand Down
1 change: 1 addition & 0 deletions lib/glossarist/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Config

DEFAULT_CLASSES = {
localized_concept: Glossarist::LocalizedConcept,
managed_concept: Glossarist::ManagedConcept,
}.freeze

attr_reader :registered_classes
Expand Down
4 changes: 2 additions & 2 deletions lib/glossarist/managed_concept_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def managed_concepts

def managed_concepts=(managed_concepts = [])
managed_concepts.each do |managed_concept|
store(ManagedConcept.new(managed_concept))
store(Config.class_for(:managed_concept).new(managed_concept))
end

@managed_concepts.values
Expand Down Expand Up @@ -53,7 +53,7 @@ def fetch(id)
# ManagedConcept ID
# @return [ManagedConcept]
def fetch_or_initialize(id)
fetch(id) or store(ManagedConcept.new(data: { id: id }))
fetch(id) or store(Config.class_for(:managed_concept).new(data: { id: id }))
end

# Adds concept to the collection. If collection contains a concept with
Expand Down
2 changes: 1 addition & 1 deletion lib/glossarist/v1_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def self.load_concept_from_file(filename)

def load_concept_from_file(filename)
concept_hash = Psych.safe_load(File.read(filename), permitted_classes: [Date])
ManagedConcept.new(generate_v2_concept_hash(concept_hash))
Config.class_for(:managed_concept).new(generate_v2_concept_hash(concept_hash))
end

private
Expand Down
7 changes: 7 additions & 0 deletions spec/unit/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@
.to(Array)
end

it "registers custom class for managed_concept" do
expect { described_class.register_class("managed_concept", Array) }
.to change { described_class.class_for("managed_concept") }
.from(Glossarist::ManagedConcept)
.to(Array)
end

it "registers custom classes with symbol names" do
expect { described_class.register_class(:foo, Array) }
.to change { described_class.class_for(:foo) }
Expand Down

0 comments on commit 825430d

Please sign in to comment.