lutaml-model 0.8.184 → 0.8.185

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7512cd09dea291c7f8ef58266e2fb60aa313701ed7bb0df1843e8c7a194dd092
4
- data.tar.gz: 720c91d86520af12e609cef406ae88b9d865450ca04c3e0fd3741114abe1b4da
3
+ metadata.gz: b26ea4574929a6043881ef30b2d06dda2f92c1d45ec4c3fd02ccaf6fd960106e
4
+ data.tar.gz: bfdd0d769e016a8b2bb81c5e501e7c4e6da1cf209da9085d5200fab95d21ae20
5
5
  SHA512:
6
- metadata.gz: b5bf83dd31ae2e125c9b886325074b4ae36a333ac637dae2ce364d2dc96850c370e457a0ecb073ece1b2ab247f8e584c000437dfe18c39ed43b4b90bf442a2c9
7
- data.tar.gz: ebb1d2c13fe1a3725ed78b64dccdfe6993b918a9969121b3569b56a877f3d9bf07f389569ab838f3a3a0ca866928f6fe5cb06bc9ef948d3ef1ff93f34b030686
6
+ metadata.gz: 687960e7428c5b0da2ffe6acba59f08a8ccc5e120fb87cd2311f00e1eec8de3f49985046a0411f29736c935e0135189630d68f692b79b6efc58c43d0606ba5ad
7
+ data.tar.gz: 1af00fce805b3d9982a25a8f79b9cac56ee5dbb697284c5080ef15c1e81d1e5759e0b1da8b97206776e852eb7456f245a11634781c0440b6023646af04b95c72
@@ -201,6 +201,12 @@ module Lutaml
201
201
  return nil if options.key?(:adapter) || options.key?(:only) ||
202
202
  options.key?(:except) || options.key?(:mappings) ||
203
203
  options.key?(:register)
204
+ # A declared model class (the `model` macro) is hydrated by the
205
+ # interpretive transformer, which instantiates the declared
206
+ # class and writes through its accessors; the plan hydrator's
207
+ # construction machinery is Serializable-bound and would build
208
+ # the declaring class instead (#1208).
209
+ return nil if model && model != self
204
210
 
205
211
  adapter_name = Lutaml::Model::Config.adapter_for(:xml)
206
212
  adapter_name = adapter_name&.name
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lutaml
4
4
  module Model
5
- VERSION = "0.8.184"
5
+ VERSION = "0.8.185"
6
6
  end
7
7
  end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe "`model` declaration under every XML adapter (#1208)" do
6
+ let(:xml) { "<book><title>Hi</title></book>" }
7
+
8
+ # Mirrors the issue repro: the Serializable class declares `model
9
+ # BookData`; the helpers live on the plain model class.
10
+ let(:build_classes) do
11
+ stub_const("BookData", Class.new do
12
+ attr_accessor :title
13
+
14
+ def shout = title.upcase
15
+ end)
16
+ stub_const("Book", Class.new(Lutaml::Model::Serializable) do
17
+ model BookData
18
+
19
+ attribute :title, :string
20
+
21
+ xml do
22
+ element "book"
23
+ map_element "title", to: :title
24
+ end
25
+ end)
26
+ end
27
+
28
+ it "returns the declared model class on the configured adapter" do
29
+ build_classes
30
+
31
+ book = Book.from_xml(xml)
32
+
33
+ expect(book).to be_a(BookData)
34
+ expect(book.shout).to eq("HI")
35
+ expect(book.title).to eq("Hi")
36
+ end
37
+
38
+ it "returns the declared model class on the leptris lane", if: defined?(Leptris) do
39
+ build_classes
40
+ previous = Lutaml::Model::Config.xml_adapter_type
41
+ Lutaml::Model::Config.xml_adapter_type = :leptris
42
+
43
+ book = Book.from_xml(xml)
44
+
45
+ expect(book).to be_a(BookData)
46
+ expect(book.shout).to eq("HI")
47
+ ensure
48
+ Lutaml::Model::Config.xml_adapter_type = previous
49
+ end
50
+
51
+ it "returns the declared model class on the nokogiri lane", if: defined?(Nokogiri) do
52
+ build_classes
53
+ previous = Lutaml::Model::Config.xml_adapter_type
54
+ Lutaml::Model::Config.xml_adapter_type = :nokogiri
55
+
56
+ book = Book.from_xml(xml)
57
+
58
+ expect(book).to be_a(BookData)
59
+ expect(book.shout).to eq("HI")
60
+ ensure
61
+ Lutaml::Model::Config.xml_adapter_type = previous
62
+ end
63
+
64
+ it "round-trips a model-class instance through to_xml" do
65
+ build_classes
66
+
67
+ data = BookData.new
68
+ data.title = "Hi"
69
+
70
+ emitted = Book.to_xml(data)
71
+ expect(emitted).to include("<title>Hi</title>")
72
+
73
+ reparsed = Book.from_xml(emitted)
74
+ expect(reparsed).to be_a(BookData)
75
+ expect(reparsed.title).to eq("Hi")
76
+ end
77
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lutaml-model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.184
4
+ version: 0.8.185
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -1852,6 +1852,7 @@ files:
1852
1852
  - spec/lutaml/model/mapping_type_validation_spec.rb
1853
1853
  - spec/lutaml/model/metaschema_types_spec.rb
1854
1854
  - spec/lutaml/model/mixed_content_spec.rb
1855
+ - spec/lutaml/model/model_declaration_from_xml_spec.rb
1855
1856
  - spec/lutaml/model/model_import_reentry_spec.rb
1856
1857
  - spec/lutaml/model/model_transformer_spec.rb
1857
1858
  - spec/lutaml/model/multiple_mapping_spec.rb