Skip to content

Commit

Permalink
fixing config bugs (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
HassanAkbar authored Feb 26, 2024
1 parent 04cc6b4 commit 513e4fe
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 12 deletions.
4 changes: 2 additions & 2 deletions lib/glossarist/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def class_for(name)
end

def register_class(class_name, klass)
@registered_classes[class_name] = klass
@registered_classes[class_name.to_sym] = klass
end

def extension_attributes
Expand All @@ -53,7 +53,7 @@ def register_class(class_name, klass)
end

def register_extension_attributes(attributes)
self.register_extension_attributes(attributes)
self.instance.register_extension_attributes(attributes)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/glossarist/localized_concept.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def to_h # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
"review_date" => review_date,
"review_decision_date" => review_decision_date,
"review_decision_event" => review_decision_event,
}.compact).merge(@extension_attributes)
}.compact).merge!(@extension_attributes)

hash
end
Expand Down
7 changes: 3 additions & 4 deletions lib/glossarist/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ def initialize(attributes = {})
def set_attribute(name, value)
public_send("#{name}=", value)
rescue NoMethodError
# adding support for camel case
if name.match?(/[A-Z]/)
if Config.extension_attributes.include?(name)
extension_attributes[name] = value
elsif name.match?(/[A-Z]/) # adding support for camel case
name = snake_case(name.to_s).to_sym
retry
elsif Config.extension_attributes.include?(name)
extension_attributes[name] = value
else
raise ArgumentError, "#{self.class.name} does not have " +
"attribute #{name} defined or the attribute is read only."
Expand Down
8 changes: 4 additions & 4 deletions spec/fixtures/relaton_cache/iso/iso_ts_14812_2022.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<bibdata type="standard" schema-version="v1.2.7">
<fetched>2023-12-12</fetched>
<bibdata type="standard" schema-version="v1.2.8">
<fetched>2024-02-26</fetched>
<title type="title-intro" format="text/plain" language="en" script="Latn">Intelligent transport systems</title>
<title type="title-main" format="text/plain" language="en" script="Latn">Vocabulary</title>
<title type="main" format="text/plain" language="en" script="Latn">Intelligent transport systems - Vocabulary</title>
Expand All @@ -10,8 +10,8 @@
<uri type="obp">https://www.iso.org/obp/ui/en/#!iso:std:79779:en</uri>
<uri type="rss">https://www.iso.org/contents/data/standard/07/97/79779.detail.rss</uri>
<docidentifier type="ISO" primary="true">ISO/TS 14812:2022</docidentifier>
<docidentifier type="iso-reference">ISO 14812:2022(E)</docidentifier>
<docidentifier type="URN">urn:iso:std:iso:ts:14812:stage-90.92:ed-1</docidentifier>
<docidentifier type="iso-reference">ISO/TS 14812:2022(E)</docidentifier>
<docidentifier type="URN">urn:iso:std:iso:ts:14812:stage-90.92</docidentifier>
<docnumber>14812</docnumber>
<date type="published">
<on>2022-04</on>
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/relaton_cache/iso/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a03026b6e0501d55c0b281625ab5eb34
5c0adcc653acd420404ff8332dee304a
53 changes: 53 additions & 0 deletions spec/unit/config_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# frozen_string_literal: true

# (c) Copyright 2021 Ribose Inc.
#

RSpec.describe Glossarist::Config do
subject { described_class.instance }

it "is a singleton class" do
expect(subject).to eq(described_class.instance)
end

context ".register_extension_attributes" do
before(:each) do
@extension_attributes = subject.extension_attributes.dup
end

after(:each) do
described_class.register_extension_attributes(@extension_attributes)
end

it "registers extension attributes" do
expect { described_class.register_extension_attributes(["foo", "bar"]) }
.to change { described_class.extension_attributes }
.from([])
.to(["foo", "bar"])
end
end

context ".register_class" do
before(:each) do
@registered_classes = subject.registered_classes.dup
end

after(:each) do
subject.instance_variable_set(:@registered_classes, @registered_classes)
end

it "registers custom classes with string names" do
expect { described_class.register_class("foo", Array) }
.to change { described_class.class_for("foo") }
.from(nil)
.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) }
.from(nil)
.to(Array)
end
end
end

0 comments on commit 513e4fe

Please sign in to comment.