lutaml-model 0.8.164 → 0.8.165
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/yeptris_adapter.rb +17 -4
- 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
- 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: 3540b4bb5e740bd2f3bda909b1e570b822f82d04703cb11347e9b8124cda5538
|
|
4
|
+
data.tar.gz: 29e6a45a50e57f6d8b6412e60251b26c118511b1fdbfa3091fb42fabd3b6d792
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b3dce5f2bc083bf9b41ab3e1959ffb828294bfedc82d102fdae4e7419df1c3b18fb707fb19388317b9a5e8f95b910ed22b8b2c124ddf4be74c7b7e1ebf5ee8f6
|
|
7
|
+
data.tar.gz: 854bd87449c9af4574ae68f44fc50ee61aa5d1906944e3a9c10c50fbc4fe8f762f6b5eec1ec48093106d7571775e9520dcf7358ff642af36a55bfe15bd3e0ac7
|
|
@@ -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
|
@@ -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,6 +22,19 @@ 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
|
+
# rubocop:disable-next Naming/VariableNumber -- upstream schema literal
|
|
31
|
+
::Yeptris::YAML.each_document(yamls, schema: :compat_11) do |doc, error|
|
|
32
|
+
warn "Skipping invalid yaml: #{error.message}" if error
|
|
33
|
+
results << doc unless error || doc.nil?
|
|
34
|
+
end
|
|
35
|
+
return results
|
|
36
|
+
end
|
|
37
|
+
|
|
25
38
|
# rubocop:disable-next Naming/VariableNumber -- upstream schema literal
|
|
26
39
|
results = Yeptris::YAML.load_stream(yamls, schema: :compat_11)
|
|
27
40
|
results.compact
|
|
@@ -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
|
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.165
|
|
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
|