lutaml-model 0.8.164 → 0.8.166
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 +4 -4
- data/lib/lutaml/model/serialization_adapter.rb +0 -1
- data/lib/lutaml/model/serialize.rb +11 -1
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/yamls/adapter/standard_adapter.rb +7 -1
- data/lib/lutaml/yamls/adapter/yeptris_adapter.rb +32 -5
- data/spec/lutaml/model/binary_attribute_value_spec.rb +32 -0
- data/spec/lutaml/model/custom_bibtex_adapter_spec.rb +3 -2
- data/spec/lutaml/model/custom_vobject_adapter_spec.rb +3 -2
- data/spec/lutaml/model/yamls/standard_adapter_spec.rb +7 -0
- data/spec/lutaml/model/yamls/yeptris_adapter_spec.rb +10 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5e26cb512515f146956b2f1f1b601a9fd810ef0fdf606e98963001e28b6fe249
|
|
4
|
+
data.tar.gz: 72e5bbd3f54f084abb92c34d63442cb0dee383851a1f4a78580b48bdf3651b8f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 682c8dd4ea109bd97314cc01f32a4ea32f489176603e4a0a115679d2c6cd3f517490da31f72c6df6c5059389f12037827d9933cf35eeb7b8e33eb86cb31d1657
|
|
7
|
+
data.tar.gz: 98beef43e550b5cd69d76824a0c3a0a5cd266477aefd6382315ef0fdb06026b8fea0662e7f76b774c5094efe396140305f2b4146d82596c7d3f5b1e8969c92a7
|
|
@@ -427,7 +427,7 @@ module Lutaml
|
|
|
427
427
|
default = using_default?(name)
|
|
428
428
|
value = self.class.apply_value_map(value, vmap, attr)
|
|
429
429
|
# Performance: Only call ensure_utf8 for string values
|
|
430
|
-
value = self.class.ensure_utf8(value) if
|
|
430
|
+
value = self.class.ensure_utf8(value) if transcode_to_utf8?(value, attr)
|
|
431
431
|
# Interpolating the writer symbol allocated a String per
|
|
432
432
|
# attribute per instance; the per-register writer table is
|
|
433
433
|
# interned once per class.
|
|
@@ -435,6 +435,16 @@ module Lutaml
|
|
|
435
435
|
using_default_for(name) if default
|
|
436
436
|
end
|
|
437
437
|
|
|
438
|
+
# A binary String from a non-text type holds bytes, not text:
|
|
439
|
+
# transcoding it to UTF-8 would silently drop every byte above 0x7F.
|
|
440
|
+
def transcode_to_utf8?(value, attr)
|
|
441
|
+
return false unless value.is_a?(::String)
|
|
442
|
+
return true unless value.encoding == Encoding::BINARY
|
|
443
|
+
|
|
444
|
+
type = attr.type(lutaml_register)
|
|
445
|
+
type.is_a?(Class) && type <= Lutaml::Model::Type::String
|
|
446
|
+
end
|
|
447
|
+
|
|
438
448
|
def determine_value(attrs, name, attr)
|
|
439
449
|
# One hash pass: a sentinel fetch distinguishes absent keys
|
|
440
450
|
# from present-nil values, replacing two key probes plus the
|
data/lib/lutaml/model/version.rb
CHANGED
|
@@ -23,8 +23,14 @@ module Lutaml
|
|
|
23
23
|
|
|
24
24
|
results
|
|
25
25
|
rescue *Lutaml::Model::Utils.yaml_parse_errors => e
|
|
26
|
+
results = parse_with_split(yamls)
|
|
27
|
+
# A stream that yields no valid document is invalid, not empty —
|
|
28
|
+
# raise so transports skip the file instead of registering a
|
|
29
|
+
# blank model.
|
|
30
|
+
raise e if results.empty?
|
|
31
|
+
|
|
26
32
|
warn "Skipping invalid yaml: #{e.message}"
|
|
27
|
-
|
|
33
|
+
results
|
|
28
34
|
end
|
|
29
35
|
|
|
30
36
|
def self.parse_with_split(yamls)
|
|
@@ -6,10 +6,10 @@ module Lutaml
|
|
|
6
6
|
module Yamls
|
|
7
7
|
module Adapter
|
|
8
8
|
# YAMLS streams over the yeptris engine (libyeptris C11), using the
|
|
9
|
-
# multi-document stream API at Psych parity (yeptris-ruby#354)
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
#
|
|
9
|
+
# multi-document stream API at Psych parity (yeptris-ruby#354) and,
|
|
10
|
+
# when the engine offers it, the tolerant per-document iterator
|
|
11
|
+
# (yeptris#921): invalid documents skip in place and the valid
|
|
12
|
+
# ones stand — no host-side splitting or re-parsing, ever.
|
|
13
13
|
class YeptrisAdapter < StandardAdapter
|
|
14
14
|
def self.parse(yamls, _options = {})
|
|
15
15
|
parse_with_stream(yamls)
|
|
@@ -22,12 +22,39 @@ module Lutaml
|
|
|
22
22
|
require_engine
|
|
23
23
|
require "yeptris/yaml"
|
|
24
24
|
|
|
25
|
+
results = []
|
|
26
|
+
if ::Yeptris::YAML.respond_to?(:each_document)
|
|
27
|
+
# Tolerant iteration (yeptris#921): the engine frames the
|
|
28
|
+
# documents and reports failures per document; the host
|
|
29
|
+
# never touches the YAML text.
|
|
30
|
+
invalid_seen = false
|
|
31
|
+
# rubocop:disable-next Naming/VariableNumber -- upstream schema literal
|
|
32
|
+
::Yeptris::YAML.each_document(yamls, schema: :compat_11) do |doc, error|
|
|
33
|
+
if error
|
|
34
|
+
invalid_seen = true
|
|
35
|
+
warn "Skipping invalid yaml: #{error.message}"
|
|
36
|
+
end
|
|
37
|
+
results << doc unless error || doc.nil?
|
|
38
|
+
end
|
|
39
|
+
# A stream that yields no valid document is invalid, not
|
|
40
|
+
# empty — raise so transports skip the file instead of
|
|
41
|
+
# registering a blank model.
|
|
42
|
+
if results.empty? && invalid_seen
|
|
43
|
+
raise Lutaml::Model::InvalidFormatError,
|
|
44
|
+
"no valid documents in the yaml stream"
|
|
45
|
+
end
|
|
46
|
+
return results
|
|
47
|
+
end
|
|
48
|
+
|
|
25
49
|
# rubocop:disable-next Naming/VariableNumber -- upstream schema literal
|
|
26
50
|
results = Yeptris::YAML.load_stream(yamls, schema: :compat_11)
|
|
27
51
|
results.compact
|
|
28
52
|
rescue Yeptris::ParseError => e
|
|
53
|
+
results = parse_with_split(yamls)
|
|
54
|
+
raise e if results.empty?
|
|
55
|
+
|
|
29
56
|
warn "Skipping invalid yaml: #{e.message}"
|
|
30
|
-
|
|
57
|
+
results
|
|
31
58
|
end
|
|
32
59
|
|
|
33
60
|
def self.require_engine
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe "Binary String attribute values" do
|
|
6
|
+
let(:bytes_type) do
|
|
7
|
+
Class.new(Lutaml::Model::Type::Value) do
|
|
8
|
+
def self.cast(value, *)
|
|
9
|
+
value.is_a?(String) ? value.b : value
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
let(:model_class) do
|
|
15
|
+
type = bytes_type
|
|
16
|
+
Class.new(Lutaml::Model::Serializable) do
|
|
17
|
+
attribute :data, type
|
|
18
|
+
attribute :text, :string
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
let(:raw) { "\xFF\x00\xC3\x28\x89".b }
|
|
23
|
+
|
|
24
|
+
it "keeps every byte a non-text type returns" do
|
|
25
|
+
expect(model_class.new(data: raw).data.bytes).to eq(raw.bytes)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "still transcodes a binary String given to a :string attribute" do
|
|
29
|
+
text = model_class.new(text: "plain".b).text
|
|
30
|
+
expect([text, text.encoding]).to eq(["plain", Encoding::UTF_8])
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -25,10 +25,11 @@
|
|
|
25
25
|
#
|
|
26
26
|
# 3. Register BibTeX format:
|
|
27
27
|
#
|
|
28
|
-
# Lutaml::Model::
|
|
28
|
+
# Lutaml::Model::FormatRegistry.register(
|
|
29
29
|
# :bibtex,
|
|
30
30
|
# mapping_class: BibtexMapping,
|
|
31
|
-
# adapter_class: BibtexAdapter
|
|
31
|
+
# adapter_class: BibtexAdapter,
|
|
32
|
+
# transformer: BibtexTransform
|
|
32
33
|
# )
|
|
33
34
|
#
|
|
34
35
|
# 4. Define BibTeX mappings using the `bibtex do` block:
|
|
@@ -99,10 +99,11 @@
|
|
|
99
99
|
#
|
|
100
100
|
# Register your custom format:
|
|
101
101
|
#
|
|
102
|
-
# Lutaml::Model::
|
|
102
|
+
# Lutaml::Model::FormatRegistry.register(
|
|
103
103
|
# :vobject,
|
|
104
104
|
# mapping_class: YourMapping,
|
|
105
|
-
# adapter_class: YourAdapter
|
|
105
|
+
# adapter_class: YourAdapter,
|
|
106
|
+
# transformer: YourTransform
|
|
106
107
|
# )
|
|
107
108
|
#
|
|
108
109
|
# == Component Types
|
|
@@ -65,6 +65,13 @@ RSpec.describe Lutaml::Model::Yamls::StandardAdapter do
|
|
|
65
65
|
end
|
|
66
66
|
end
|
|
67
67
|
|
|
68
|
+
context "with a fully-invalid stream" do
|
|
69
|
+
it "raises instead of returning a blank document set" do
|
|
70
|
+
expect { described_class.parse("not: valid: yaml: [") }
|
|
71
|
+
.to raise_error(Psych::SyntaxError)
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
68
75
|
context "with single document" do
|
|
69
76
|
let(:single_yaml_doc) do
|
|
70
77
|
<<~YAMLS
|
|
@@ -66,5 +66,15 @@ RSpec.describe Lutaml::Yamls::Adapter::YeptrisAdapter, if: Lutaml::Yamls::Adapte
|
|
|
66
66
|
results = described_class.parse("name: John\nage: 30\n")
|
|
67
67
|
expect(results).to eq([{ "name" => "John", "age" => 30 }])
|
|
68
68
|
end
|
|
69
|
+
|
|
70
|
+
it "raises on a fully-invalid stream instead of returning a blank set" do
|
|
71
|
+
expect { described_class.parse("not: valid: yaml: [") }
|
|
72
|
+
.to raise_error(StandardError)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "tolerates mixed streams but raises when nothing valid remains" do
|
|
76
|
+
results = described_class.parse("name: a\n---\nbad: [\n---\nname: c\n")
|
|
77
|
+
expect(results).to eq([{ "name" => "a" }, { "name" => "c" }])
|
|
78
|
+
end
|
|
69
79
|
end
|
|
70
80
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lutaml-model
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.8.
|
|
4
|
+
version: 0.8.166
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: base64
|
|
@@ -1749,6 +1749,7 @@ files:
|
|
|
1749
1749
|
- spec/lutaml/model/attribute_restriction_spec.rb
|
|
1750
1750
|
- spec/lutaml/model/attribute_spec.rb
|
|
1751
1751
|
- spec/lutaml/model/attributes_memo_clear_race_spec.rb
|
|
1752
|
+
- spec/lutaml/model/binary_attribute_value_spec.rb
|
|
1752
1753
|
- spec/lutaml/model/boot_manifest_spec.rb
|
|
1753
1754
|
- spec/lutaml/model/cached_type_resolver_spec.rb
|
|
1754
1755
|
- spec/lutaml/model/cardinality_strict_spec.rb
|