lutaml-xsd 1.0.1 → 1.0.2

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: 17d40234cd89518b6025cc5a7fb3fd528a2664f9e46928391141de6d6d190ca7
4
- data.tar.gz: e74a794d5b769ef44809db6522967e697da1d84d3ef57eded7a7878a920f7d38
3
+ metadata.gz: e8d8b1ad8e625ee8cab24750b1431684ee5a7129c5fbd94d2f238bc1742eaf0b
4
+ data.tar.gz: fd018a29d844d9a4c2e6ae3b7b59a2c6520e4a3ca2a9f5c6ab59548a125806bb
5
5
  SHA512:
6
- metadata.gz: 0e4ef4980e59697d4089eae07c8f5bddf3019f02d25c9b73a4981937cf2fc1efa2c07a14e63251e59d044390ae7871b6f0d481c8eda16030a6529bdac18bc97a
7
- data.tar.gz: 3495e42fa5fc29c2bb01682c4aa28e1bdb111459069b22a2d16a07bd92446b7367c5161ec848a36308a8b5645ec32e4071a63798a96ed87875225d1c12264e8b
6
+ metadata.gz: 0f2f77d3f47cb88123d7addac782e80f41f2ee6362758841aabfc90934976b3ac26e7d47e7eadd975c6d5744acfa1d2f8a53462e949f486e3ad5b0152a2bfec5
7
+ data.tar.gz: 1da9d9df59da0f84fb0f1f374b7b28e7ff1d3d83ced963513482630dec9954b2fcffc5482c81134ebe1d160b6920c2248ad5008d722ec9ad7f846da6746da20e
@@ -9,6 +9,7 @@ module Lutaml
9
9
  attribute :xmlns, :string
10
10
  attribute :version, :string
11
11
  attribute :imported, :boolean
12
+ attribute :included, :boolean
12
13
  attribute :final_default, :string
13
14
  attribute :block_default, :string
14
15
  attribute :target_namespace, :string
@@ -57,7 +58,7 @@ module Lutaml
57
58
 
58
59
  def import_from_schema(model, value)
59
60
  value.each do |schema|
60
- setup_import_and_include("import", model, schema, namespace: schema["attributes"]["namespace"])
61
+ setup_import_and_include("import", model, schema, namespace: schema.attributes["namespace"].value)
61
62
  end
62
63
  end
63
64
 
@@ -77,16 +78,18 @@ module Lutaml
77
78
  end
78
79
 
79
80
  def include_to_schema(model, parent, _doc)
80
- model.includes.each_with_index do |schema_hash, index|
81
+ return if model.included
82
+
83
+ model.included = true
84
+ model.includes.each do |schema_hash|
81
85
  parent.add_child(schema_hash.to_xml)
82
- model.includes.delete_at(index)
83
86
  end
84
87
  end
85
88
 
86
89
  private
87
90
 
88
91
  def setup_import_and_include(klass, model, schema, args = {})
89
- instance = init_instance_of(klass, schema["attributes"] || {}, args)
92
+ instance = init_instance_of(klass, schema.attributes || {}, args)
90
93
  annotation_object(instance, schema)
91
94
  model.send("#{klass}s") << instance
92
95
  schema_path = instance.schema_path
@@ -97,17 +100,9 @@ module Lutaml
97
100
  self.class.remove_in_progress(schema_path)
98
101
  end
99
102
 
100
- def dig_schema_location(schema_hash)
101
- schema_hash&.dig("__schema_location", :schema_location)
102
- end
103
-
104
- def schema_location?(schema_hash)
105
- schema_hash&.dig("__schema_location")&.key?(:schema_location)
106
- end
107
-
108
103
  def init_instance_of(klass, schema_hash, args = {})
109
- args[:id] = schema_hash["id"]
110
- args[:schema_path] = dig_schema_location(schema_hash)
104
+ args[:id] = schema_hash["id"].value if schema_hash&.key?("id")
105
+ args[:schema_path] = schema_hash["schemaLocation"].value if schema_hash&.key?("schemaLocation")
111
106
  Lutaml::Xsd.const_get(klass.capitalize).new(**args)
112
107
  end
113
108
 
@@ -132,11 +127,11 @@ module Lutaml
132
127
  end
133
128
 
134
129
  def annotation_object(instance, schema)
135
- elements = schema["elements"] || {}
136
- annotation_key = elements.keys.find { |key| key.include?("annotation") }
130
+ elements = schema.children || []
131
+ annotation_key = elements.find { |element| element.unprefixed_name == "annotation" }
137
132
  return unless annotation_key
138
133
 
139
- instance.annotation = Annotation.apply_mappings(elements[annotation_key], :xml)
134
+ instance.annotation = Annotation.apply_mappings(annotation_key, :xml)
140
135
  end
141
136
 
142
137
  class << self
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lutaml
4
4
  module Xsd
5
- VERSION = "1.0.1"
5
+ VERSION = "1.0.2"
6
6
  end
7
7
  end
data/lib/lutaml/xsd.rb CHANGED
@@ -2,11 +2,31 @@
2
2
 
3
3
  require "zeitwerk"
4
4
  require "lutaml/model"
5
- require_relative "xsd/xsd"
6
-
5
+ require "lutaml/model/xml_adapter/nokogiri_adapter"
7
6
  Lutaml::Model::Config.xml_adapter_type = :nokogiri
8
7
 
9
8
  loader = Zeitwerk::Loader.for_gem(warn_on_extra_files: true)
9
+ loader.push_dir(__dir__, namespace: Lutaml)
10
10
  loader.push_dir("#{__dir__}/xsd", namespace: Lutaml::Xsd)
11
- loader.ignore("#{__dir__}/lib/lutaml/xsd.rb")
12
11
  loader.setup
12
+
13
+ module Lutaml
14
+ module Xsd
15
+ class Error < StandardError; end
16
+
17
+ module_function
18
+
19
+ def parse(xsd, location: nil, nested_schema: false)
20
+ Schema.reset_processed_schemas unless nested_schema
21
+
22
+ Glob.path_or_url(location)
23
+ Schema.from_xml(xsd)
24
+ end
25
+ end
26
+ end
27
+
28
+ begin
29
+ loader.eager_load(force: true)
30
+ rescue Zeitwerk::NameError => e
31
+ flunk e.message
32
+ end
data/lib/lutaml_xsd.rb ADDED
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lutaml/xsd"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lutaml-xsd
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-01-30 00:00:00.000000000 Z
11
+ date: 2025-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lutaml-model
@@ -106,7 +106,7 @@ files:
106
106
  - lib/lutaml/xsd/unique.rb
107
107
  - lib/lutaml/xsd/version.rb
108
108
  - lib/lutaml/xsd/white_space.rb
109
- - lib/lutaml/xsd/xsd.rb
109
+ - lib/lutaml_xsd.rb
110
110
  - lutaml-xsd.gemspec
111
111
  - sig/lutaml/xsd.rbs
112
112
  homepage: https://github.com/lutaml/expressir
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lutaml
4
- module Xsd
5
- class Error < StandardError; end
6
-
7
- module_function
8
-
9
- def parse(xsd, location: nil, nested_schema: false)
10
- Schema.reset_processed_schemas unless nested_schema
11
-
12
- Glob.path_or_url(location)
13
- Schema.from_xml(xsd)
14
- end
15
- end
16
- end