lutaml-xsd 1.0.0 → 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: a4296cdc53ac951e9dabd94e87350ea4d82e7691fcd879e5ea38d9ac619c620e
4
- data.tar.gz: a9e1191c508dabc0bc942e86b210f06d4c27815ab10cf5fbdc322bbde0b59f68
3
+ metadata.gz: e8d8b1ad8e625ee8cab24750b1431684ee5a7129c5fbd94d2f238bc1742eaf0b
4
+ data.tar.gz: fd018a29d844d9a4c2e6ae3b7b59a2c6520e4a3ca2a9f5c6ab59548a125806bb
5
5
  SHA512:
6
- metadata.gz: 2d69274700a75e1756c82103c095a0bf3b5b56fb0c9d9c35da98112afcbca422e37cfed00d46579f0969fec4392ae04b993f57e58f1aaea35e513d6ae39577ff
7
- data.tar.gz: 7ffa3d40825726c740a29cac23685e32aff7f4295603634361524305b7579bbf4b02194582b78f12da42c6923657c682b7182d863b08bbd9267ce3190bef6149
6
+ metadata.gz: 0f2f77d3f47cb88123d7addac782e80f41f2ee6362758841aabfc90934976b3ac26e7d47e7eadd975c6d5744acfa1d2f8a53462e949f486e3ad5b0152a2bfec5
7
+ data.tar.gz: 1da9d9df59da0f84fb0f1f374b7b28e7ff1d3d83ced963513482630dec9954b2fcffc5482c81134ebe1d160b6920c2248ad5008d722ec9ad7f846da6746da20e
@@ -38,7 +38,7 @@ module Lutaml
38
38
  end
39
39
 
40
40
  def include_schema(schema_location)
41
- return unless location? || schema_location
41
+ return unless location? && schema_location
42
42
 
43
43
  schema_path = schema_location_path(schema_location)
44
44
  url? ? http_get(schema_path) : File.read(schema_path)
@@ -19,7 +19,7 @@ module Lutaml
19
19
  end
20
20
 
21
21
  def fetch_schema
22
- Glob.include_schema(schema_path) if schema_path
22
+ Glob.include_schema(schema_path) if schema_path && Glob.location?
23
23
  end
24
24
  end
25
25
  end
@@ -8,6 +8,8 @@ module Lutaml
8
8
  attribute :lang, :string
9
9
  attribute :xmlns, :string
10
10
  attribute :version, :string
11
+ attribute :imported, :boolean
12
+ attribute :included, :boolean
11
13
  attribute :final_default, :string
12
14
  attribute :block_default, :string
13
15
  attribute :target_namespace, :string
@@ -56,14 +58,16 @@ module Lutaml
56
58
 
57
59
  def import_from_schema(model, value)
58
60
  value.each do |schema|
59
- setup_import_and_include("import", model, schema, namespace: schema["namespace"])
61
+ setup_import_and_include("import", model, schema, namespace: schema.attributes["namespace"].value)
60
62
  end
61
63
  end
62
64
 
63
65
  def import_to_schema(model, parent, _doc)
64
- model.imports.each_with_index do |imported_schema, index|
66
+ return if model.imported
67
+
68
+ model.imported = true
69
+ model.imports.each do |imported_schema|
65
70
  parent.add_child(imported_schema.to_xml)
66
- model.imports.delete_at(index)
67
71
  end
68
72
  end
69
73
 
@@ -74,16 +78,18 @@ module Lutaml
74
78
  end
75
79
 
76
80
  def include_to_schema(model, parent, _doc)
77
- 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|
78
85
  parent.add_child(schema_hash.to_xml)
79
- model.includes.delete_at(index)
80
86
  end
81
87
  end
82
88
 
83
89
  private
84
90
 
85
91
  def setup_import_and_include(klass, model, schema, args = {})
86
- instance = init_instance_of(klass, schema, args)
92
+ instance = init_instance_of(klass, schema.attributes || {}, args)
87
93
  annotation_object(instance, schema)
88
94
  model.send("#{klass}s") << instance
89
95
  schema_path = instance.schema_path
@@ -94,17 +100,9 @@ module Lutaml
94
100
  self.class.remove_in_progress(schema_path)
95
101
  end
96
102
 
97
- def dig_schema_location(schema_hash)
98
- schema_hash&.dig("__schema_location", :schema_location)
99
- end
100
-
101
- def schema_location?(schema_hash)
102
- schema_hash&.dig("__schema_location")&.key?(:schema_location)
103
- end
104
-
105
103
  def init_instance_of(klass, schema_hash, args = {})
106
- args[:id] = schema_hash["id"]
107
- 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")
108
106
  Lutaml::Xsd.const_get(klass.capitalize).new(**args)
109
107
  end
110
108
 
@@ -118,7 +116,7 @@ module Lutaml
118
116
 
119
117
  def schema_by_location_or_instance(instance)
120
118
  schema_path = instance.schema_path
121
- return unless schema_path
119
+ return unless schema_path && Glob.location?
122
120
 
123
121
  self.class.processed_schemas[schema_path] ||
124
122
  Lutaml::Xsd.parse(
@@ -129,10 +127,11 @@ module Lutaml
129
127
  end
130
128
 
131
129
  def annotation_object(instance, schema)
132
- annotation_key = schema.keys.find { |key| key.include?("annotation") }
130
+ elements = schema.children || []
131
+ annotation_key = elements.find { |element| element.unprefixed_name == "annotation" }
133
132
  return unless annotation_key
134
133
 
135
- instance.annotation = Annotation.apply_mappings(schema[annotation_key], :xml)
134
+ instance.annotation = Annotation.apply_mappings(annotation_key, :xml)
136
135
  end
137
136
 
138
137
  class << self
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lutaml
4
4
  module Xsd
5
- VERSION = "1.0.0"
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"
data/lutaml-xsd.gemspec CHANGED
@@ -32,6 +32,6 @@ Gem::Specification.new do |spec|
32
32
 
33
33
  spec.test_files = `git ls-files -- {spec}/*`.split("\n")
34
34
 
35
- spec.add_dependency "lutaml-model", "~> 0.3"
35
+ spec.add_dependency "lutaml-model", "~> 0.5"
36
36
  spec.add_dependency "zeitwerk"
37
37
  end
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.0
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-12-31 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
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.3'
19
+ version: '0.5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.3'
26
+ version: '0.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: zeitwerk
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -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
@@ -117,7 +117,7 @@ metadata:
117
117
  source_code_uri: https://github.com/lutaml/expressir
118
118
  changelog_uri: https://github.com/lutaml/lutaml-xsd/releases
119
119
  rubygems_mfa_required: 'true'
120
- post_install_message:
120
+ post_install_message:
121
121
  rdoc_options: []
122
122
  require_paths:
123
123
  - lib
@@ -133,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  version: '0'
134
134
  requirements: []
135
135
  rubygems_version: 3.3.27
136
- signing_key:
136
+ signing_key:
137
137
  specification_version: 4
138
138
  summary: Library for XML Schema Definition (XSD) files
139
139
  test_files: []
@@ -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