lutaml-model 0.8.156 → 0.8.158

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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/opal.yml +5 -17
  3. data/.rubocop.yml +10 -0
  4. data/Rakefile +5 -1
  5. data/docs/_guides/opal.adoc +11 -0
  6. data/docs/_pages/serialization_adapters.adoc +47 -2
  7. data/lib/compat/opal/monitor.rb +31 -0
  8. data/lib/compat/opal/moxml/adapter/customized_rexml/entity_reference.rb +9 -0
  9. data/lib/compat/opal/moxml/adapter/customized_rexml/formatter.rb +225 -0
  10. data/lib/compat/opal/moxml/adapter/customized_rexml.rb +11 -0
  11. data/lib/compat/opal/moxml_boot.rb +66 -71
  12. data/lib/compat/opal/objectspace_shim.rb +23 -0
  13. data/lib/compat/opal/rexml/namespace.rb +59 -0
  14. data/lib/compat/opal/rexml/parsers/baseparser.rb +1016 -0
  15. data/lib/compat/opal/rexml/source.rb +214 -0
  16. data/lib/compat/opal/rexml/text.rb +426 -0
  17. data/lib/compat/opal/rexml/xmltokens.rb +45 -0
  18. data/lib/compat/opal/rexml_compat.rb +85 -0
  19. data/lib/lutaml/model/adapter_resolver.rb +29 -0
  20. data/lib/lutaml/model/cached_type_resolver/concurrent_map_cache.rb +3 -1
  21. data/lib/lutaml/model/cached_type_resolver/mutex_hash_cache.rb +3 -1
  22. data/lib/lutaml/model/cached_type_resolver.rb +13 -22
  23. data/lib/lutaml/model/collection.rb +54 -5
  24. data/lib/lutaml/model/mapping/mapping_rule.rb +28 -4
  25. data/lib/lutaml/model/serialize/builder.rb +1 -1
  26. data/lib/lutaml/model/serialize/format_conversion.rb +26 -1
  27. data/lib/lutaml/model/serialize.rb +6 -1
  28. data/lib/lutaml/model/services/rule_value_extractor.rb +39 -35
  29. data/lib/lutaml/model/utils.rb +8 -1
  30. data/lib/lutaml/model/version.rb +1 -1
  31. data/lib/lutaml/xml/adapter/oga_adapter.rb +4 -0
  32. data/lib/lutaml/xml/adapter/rexml_adapter.rb +4 -0
  33. data/lib/lutaml/xml/leptris/plan_hydrator.rb +14 -7
  34. data/lib/lutaml/xml/leptris/plan_order.rb +24 -7
  35. data/lib/lutaml/xml/model_transform.rb +21 -3
  36. data/lib/lutaml/xml/parse_session.rb +4 -3
  37. data/lib/lutaml/xml/xml_attribute.rb +31 -11
  38. data/lutaml-model.gemspec +6 -4
  39. data/spec/lutaml/model/collection_scalar_maps_spec.rb +58 -0
  40. data/spec/lutaml/xml/opal_xml_spec.rb +10 -0
  41. metadata +16 -4
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Vendored from lutaml/moxml 0.5.167's lib/compat/opal/rexml_compat.rb
4
+ # (the compat surface moxml 0.6 no longer ships). The shadows under
5
+ # rexml/ patch the REXML stdlib gem for Opal — multi-byte escape
6
+ # regexes in rexml/source.rb, namespace resolution, text decoding and
7
+ # the baseparser scanner — which the Opal boot requires on every
8
+ # moxml line. Loaded by the Opal Rakefile before spec_helper.
9
+ require "corelib/array/pack"
10
+
11
+ # backtick_javascript: true
12
+
13
+ require "corelib/array/pack"
14
+
15
+ unless defined?(StringScanner::Version)
16
+ class StringScanner
17
+ Version = "3.0.8"
18
+ end
19
+ end
20
+
21
+ unless String.method_defined?(:force_encoding)
22
+ class String
23
+ def force_encoding(*)
24
+ self
25
+ end
26
+ end
27
+ end
28
+
29
+ unless defined?(Encoding)
30
+ module ::Encoding
31
+ UTF_8 = "UTF-8"
32
+ ASCII_8BIT = "ASCII-8BIT"
33
+ end
34
+ end
35
+
36
+ unless String.method_defined?(:encode)
37
+ class String
38
+ def encode(*)
39
+ self
40
+ end
41
+ end
42
+ end
43
+
44
+ # Opal defines mutable String methods as raising NotImplementedError.
45
+ # Override with functional equivalents that return new strings.
46
+ class String
47
+ def <<(str)
48
+ `return self + #{str}.to_s`
49
+ end
50
+
51
+ def chomp!(sep = nil)
52
+ `
53
+ var r = #{chomp(sep)};
54
+ return r === self ? nil : r;
55
+ `
56
+ end
57
+
58
+ def gsub!(pattern, replacement, &block)
59
+ `
60
+ var r = #{gsub(pattern, replacement, &block)};
61
+ return r === self ? nil : r;
62
+ `
63
+ end
64
+
65
+ def squeeze!(*sets)
66
+ `
67
+ var r = #{squeeze(*sets)};
68
+ return r === self ? nil : r;
69
+ `
70
+ end
71
+
72
+ def strip!
73
+ `
74
+ var r = #{strip};
75
+ return r === self ? nil : r;
76
+ `
77
+ end
78
+ end
79
+
80
+ class StringIO
81
+ def <<(str)
82
+ write(str)
83
+ self
84
+ end
85
+ end
@@ -29,6 +29,21 @@ module Lutaml
29
29
  #
30
30
  class AdapterResolver
31
31
  class << self
32
+ # Adapters on the deprecation path. moxml is the only supported
33
+ # XML facade going forward, and its default engine (Nokogiri,
34
+ # with the leptris native engine preferred when present) is the
35
+ # supported lane; the pure-Ruby REXML and Oga engines remain
36
+ # loadable but select for the last time in the 0.8 line.
37
+ DEPRECATED_ADAPTERS = {
38
+ %i[xml rexml] => "the REXML engine is deprecated; moxml's " \
39
+ "default engine (Nokogiri, or the leptris " \
40
+ "native engine when present) is the supported " \
41
+ "XML lane",
42
+ %i[xml oga] => "the Oga engine is deprecated; moxml's default " \
43
+ "engine (Nokogiri, or the leptris native engine " \
44
+ "when present) is the supported XML lane",
45
+ }.freeze
46
+
32
47
  # --- Resolution ---
33
48
 
34
49
  # Resolve the adapter class for a format using the full resolution chain.
@@ -215,12 +230,26 @@ module Lutaml
215
230
  adapter = format.to_s
216
231
  type = normalize_type_name(type_name, format)
217
232
 
233
+ warn_deprecated_adapter(format, type_name)
218
234
  load_adapter_file(adapter, type)
219
235
  load_moxml_adapter(type_name, format)
220
236
 
221
237
  class_for(adapter, type)
222
238
  end
223
239
 
240
+ # One deprecation warning per (format, adapter) per process.
241
+ def warn_deprecated_adapter(format, type_name)
242
+ message = DEPRECATED_ADAPTERS[[format, type_name.to_sym]]
243
+ return if message.nil? || warned_deprecated.key?([format, type_name])
244
+
245
+ warned_deprecated[[format, type_name]] = true
246
+ warn "[Lutaml::Model] DEPRECATED: #{message}."
247
+ end
248
+
249
+ def warned_deprecated
250
+ @warned_deprecated ||= {}
251
+ end
252
+
224
253
  # Normalize type name to file/class name pattern.
225
254
  #
226
255
  # @param type_name [Symbol] raw type name
@@ -29,7 +29,9 @@ module Lutaml
29
29
 
30
30
  def clear_context(context_id)
31
31
  @store.each_key do |key|
32
- @store.delete(key) if key[0] == context_id
32
+ # Non-Array keys are the bare, nil-context form (see
33
+ # CachedTypeResolver#type_cache_key).
34
+ @store.delete(key) if (key.is_a?(Array) ? key[0] : nil) == context_id
33
35
  end
34
36
  end
35
37
 
@@ -34,7 +34,9 @@ module Lutaml
34
34
 
35
35
  def clear_context(context_id)
36
36
  @mutex.synchronize do
37
- @store.delete_if { |key, _| key[0] == context_id }
37
+ # Non-Array keys are the bare, nil-context form (see
38
+ # CachedTypeResolver#type_cache_key).
39
+ @store.delete_if { |key, _| (key.is_a?(Array) ? key[0] : nil) == context_id }
38
40
  end
39
41
  end
40
42
 
@@ -65,13 +65,7 @@ module Lutaml
65
65
  def resolve(name, context, materialize: true)
66
66
  return @delegate.resolve(name, context, materialize: false) unless materialize
67
67
 
68
- cache_key = if name.is_a?(Class)
69
- [context_id_for(context), name]
70
- else
71
- build_cache_key(name, context)
72
- end
73
-
74
- @cache_backend.fetch_or_store(cache_key) do
68
+ @cache_backend.fetch_or_store(type_cache_key(name, context)) do
75
69
  @delegate.resolve(name, context)
76
70
  end
77
71
  end
@@ -82,13 +76,7 @@ module Lutaml
82
76
  # @param context [TypeContext, nil] The resolution context
83
77
  # @return [Boolean] true if type can be resolved
84
78
  def resolvable?(name, context)
85
- cache_key = if name.is_a?(Class)
86
- [context_id_for(context), name]
87
- else
88
- build_cache_key(name, context)
89
- end
90
-
91
- return true if @cache_backend.key?(cache_key)
79
+ return true if @cache_backend.key?(type_cache_key(name, context))
92
80
 
93
81
  @delegate.resolvable?(name, context)
94
82
  end
@@ -133,14 +121,17 @@ module Lutaml
133
121
 
134
122
  private
135
123
 
136
- # Build a cache key from name and context.
137
- # Uses array for faster comparison than string concatenation.
138
- #
139
- # @param name [Symbol, String] The type name
140
- # @param context [TypeContext, nil] The resolution context
141
- # @return [Array] The cache key (faster than string)
142
- def build_cache_key(name, context)
143
- [context_id_for(context), name.to_sym]
124
+ # Composite cache key: `[context_id, name]` when a context is present,
125
+ # otherwise the bare name (Symbol or Class). The bare form avoids one
126
+ # Array allocation per resolution in the common single-register run;
127
+ # it cannot collide with composite keys since Arrays and
128
+ # Symbols/Classes never match as Hash keys. Keys belonging to the nil
129
+ # context are therefore the non-Array ones (see the backends'
130
+ # #clear_context).
131
+ def type_cache_key(name, context)
132
+ bare = name.is_a?(Class) ? name : name.to_sym
133
+ cid = context_id_for(context)
134
+ cid ? [cid, bare] : bare
144
135
  end
145
136
 
146
137
  # A nil context (e.g. a register ID that has no registered type
@@ -75,6 +75,12 @@ module Lutaml
75
75
  end
76
76
  end
77
77
 
78
+ # Frozen per-subclass ivar name for the `collection` accessors —
79
+ # see the instance-method memo below.
80
+ def collection_ivar_name
81
+ @collection_ivar_name ||= :"@#{instance_name}"
82
+ end
83
+
78
84
  attr_reader :instance_type,
79
85
  :instance_name,
80
86
  :sort_by_field,
@@ -325,7 +331,11 @@ module Lutaml
325
331
  mappings = mappings_for(format)
326
332
  data = super
327
333
 
328
- if !collection_structured_format?(format) && mappings.no_root? && !mappings.root_mapping
334
+ # Scalar mappings make the document hash-shaped (#1086): the
335
+ # unwrap below would strip it back to a bare items array and
336
+ # drop the scalar keys.
337
+ if !collection_structured_format?(format) && mappings.no_root? &&
338
+ !mappings.root_mapping && !collection_has_scalar_mappings?(format)
329
339
  unwrap_unwrapped_data(data)
330
340
  else
331
341
  data
@@ -339,19 +349,50 @@ module Lutaml
339
349
  data = wrap_unwrapped_input(format, mappings, data)
340
350
  end
341
351
 
352
+ # Hash-shaped documents (scalar mappings declared, #1086) walk
353
+ # the rules like any model: the collection flag would treat the
354
+ # document as the bare items array and lose the scalar keys.
355
+ if !collection_structured_format?(format) &&
356
+ collection_has_scalar_mappings?(format) && data.is_a?(::Hash)
357
+ return super(format, data, options.merge(from_collection: true))
358
+ end
359
+
342
360
  super(format, data, options.merge(from_collection: true))
343
361
  end
344
362
 
345
363
  def of(format, data, options = {})
346
364
  mappings = mappings_for(format)
347
365
 
348
- if !collection_structured_format?(format) && mappings.no_root? && !mappings.root_mapping
366
+ # Hash-shaped documents carrying a declared scalar key (#1086)
367
+ # are already keyed; the no-root wrap would double-nest them.
368
+ # Bare arrays (the legacy items document), keyed-element
369
+ # documents (child_mappings walks the hash keys), and scalar-less
370
+ # collections all keep the historical wrap.
371
+ if !collection_structured_format?(format) && mappings.no_root? &&
372
+ !mappings.root_mapping && data.is_a?(::Array)
373
+ data = { mappings.find_by_to!(instance_name).name => data }
374
+ elsif !collection_structured_format?(format) && data.is_a?(::Hash) &&
375
+ collection_has_scalar_mappings?(format) &&
376
+ !(data.keys & collection_scalar_mapping_names(format)).empty?
377
+ # keep the keyed document as-is
378
+ elsif !collection_structured_format?(format) && mappings.no_root? &&
379
+ !mappings.root_mapping
349
380
  data = { mappings.find_by_to!(instance_name).name => data }
350
381
  end
351
382
 
352
383
  super(format, data, options.merge(from_collection: true))
353
384
  end
354
385
 
386
+ # Names of the collection's scalar (non-instance) key-value
387
+ # mappings (#1086).
388
+ def collection_scalar_mapping_names(format)
389
+ instance = instance_name
390
+ mappings_for(format).mappings
391
+ .reject { |rule| rule.to == instance }
392
+ .flat_map { |rule| Array(rule.name) }
393
+ .compact
394
+ end
395
+
355
396
  # Hook: returns true for formats that use structured (tree-based) serialization
356
397
  # like XML. Key-value formats (JSON, YAML, TOML) return false (default).
357
398
  # XML overrides to return true.
@@ -431,7 +472,11 @@ module Lutaml
431
472
 
432
473
  attr_reader :lutaml_register
433
474
 
434
- def initialize(items = [],
475
+ # Shared frozen empty array for the constructor's default argument;
476
+ # `items` is only read in initialize, never mutated.
477
+ EMPTY_ITEMS = [].freeze
478
+
479
+ def initialize(items = EMPTY_ITEMS,
435
480
  lutaml_register: Lutaml::Model::Config.default_register)
436
481
  super()
437
482
 
@@ -460,12 +505,16 @@ lutaml_register: Lutaml::Model::Config.default_register)
460
505
  super(format, options.merge(collection: true))
461
506
  end
462
507
 
508
+ # The ivar name is static per subclass (set by `instances`); the
509
+ # dynamic :"@#{...}" symbol minted per access was 11% of a
510
+ # YAML-materialization profile's allocations (56k per 60 docs on
511
+ # the glossarist corpus). The name is memoized on the class.
463
512
  def collection
464
- instance_variable_get(:"@#{self.class.instance_name}")
513
+ instance_variable_get(self.class.collection_ivar_name)
465
514
  end
466
515
 
467
516
  def collection=(collection)
468
- instance_variable_set(:"@#{self.class.instance_name}", collection)
517
+ instance_variable_set(self.class.collection_ivar_name, collection)
469
518
  sort_items!
470
519
  build_index_caches!
471
520
  end
@@ -566,18 +566,42 @@ context = nil, pre_cast: false)
566
566
  end
567
567
  end
568
568
 
569
+ # Pooled invokers for symbol/string custom methods, keyed by
570
+ # [mapper class, method]. The receiver is stateless in the #550
571
+ # contract — it receives the model and value as arguments — but a
572
+ # fresh mapper_class.new per rule application ran the full
573
+ # Serializable constructor chain on every call (33% of a YAML
574
+ # materialization profile on the glossarist corpus). One receiver
575
+ # per (class, method) is pooled, with the arity probe resolved
576
+ # once alongside it. A custom method that stashes instance state
577
+ # on the receiver would observe cross-call persistence — today's
578
+ # fresh receiver discarded that state between calls, so such
579
+ # methods were already broken call-over-call.
580
+ def custom_method_invokers
581
+ @custom_method_invokers ||= {}
582
+ end
583
+
584
+ def custom_method_invoker(mapper_class, custom)
585
+ custom_method_invokers[[mapper_class, custom]] ||= begin
586
+ receiver = mapper_class.new
587
+ { receiver: receiver,
588
+ context_arity:
589
+ self.class.custom_method_arity(receiver.class, custom).to_i >= 3 }
590
+ end
591
+ end
592
+
569
593
  def handle_custom_method(model, value, mapper_class, context = nil)
570
594
  custom = custom_methods[:from]
571
595
  return if !custom || value.nil?
572
596
 
573
597
  if custom.is_a?(String) || custom.is_a?(Symbol)
574
- target = mapper_class.new
598
+ invoker = custom_method_invoker(mapper_class, custom)
575
599
  # lutaml-model#550: custom methods may declare a third context
576
600
  # parameter to receive the options passed to `from_*`.
577
- if self.class.custom_method_arity(target.class, custom).to_i >= 3
578
- target.public_send(custom, model, value, context)
601
+ if invoker[:context_arity]
602
+ invoker[:receiver].public_send(custom, model, value, context)
579
603
  else
580
- target.public_send(custom, model, value)
604
+ invoker[:receiver].public_send(custom, model, value)
581
605
  end
582
606
  else
583
607
  # Callable (proc/lambda): transforms the value and the rule
@@ -33,7 +33,7 @@ module Lutaml
33
33
  # @param attrs [Hash] Attribute values (ignored when block given)
34
34
  # @param options [Hash] Options (ignored when block given)
35
35
  # @param block [Proc, nil] Optional builder block
36
- def initialize(attrs = {}, options = {}, &block)
36
+ def initialize(attrs = EMPTY_HASH, options = EMPTY_HASH, &block)
37
37
  # Call parent initialize
38
38
  super(attrs, options)
39
39
 
@@ -433,7 +433,18 @@ module Lutaml
433
433
  resolve_serialization_mapping_option(format, options)
434
434
 
435
435
  if instance.is_a?(Array)
436
- return instance.map { |item| public_send(:"as_#{format}", item) }
436
+ # Collection subclasses that declare scalar key-value mappings
437
+ # serialize hash-shaped (#1086): their rules include
438
+ # non-instance keys, so the per-item map would silently drop
439
+ # them. Plain Arrays and legacy collections (instances-only
440
+ # mappings) keep the per-item map.
441
+ if instance.is_a?(Lutaml::Model::Collection) &&
442
+ !collection_structured_format?(format) &&
443
+ collection_has_scalar_mappings?(format)
444
+ # fall through to the rule walk below
445
+ else
446
+ return instance.map { |item| public_send(:"as_#{format}", item) }
447
+ end
437
448
  end
438
449
 
439
450
  unless instance.is_a?(model)
@@ -454,6 +465,20 @@ module Lutaml
454
465
  transformer.model_to_data(self, instance, format, options)
455
466
  end
456
467
 
468
+ # Whether the bound Collection class declares key-value mappings
469
+ # beyond its instance collection rule (#1086). Such mappings make
470
+ # the document hash-shaped (instance key plus scalar keys) instead
471
+ # of the legacy bare items array.
472
+ def collection_has_scalar_mappings?(format)
473
+ return false unless model < Lutaml::Model::Collection
474
+
475
+ mappings = model.mappings_for(format)
476
+ instance_name = model.instance_name
477
+ mappings.mappings.any? { |rule| rule.to != instance_name }
478
+ rescue StandardError
479
+ false
480
+ end
481
+
457
482
  # Hook for format-specific pre-serialization logic.
458
483
  # XML overrides to resolve XML mapping imports.
459
484
  #
@@ -43,6 +43,11 @@ module Lutaml
43
43
  # getters default to it instead of a `*args` splat.
44
44
  NO_ARG = Object.new.freeze
45
45
 
46
+ # Shared frozen empty hash for constructor default arguments. The init
47
+ # walk only reads attrs/options, so one frozen instance replaces the
48
+ # per-instantiation `{}` defaults (68k+ allocations per corpus parse).
49
+ EMPTY_HASH = {}.freeze
50
+
46
51
  INTERNAL_ATTRIBUTES = %i[@using_default @lutaml_register @lutaml_parent @lutaml_root
47
52
  @register_records].freeze
48
53
 
@@ -162,7 +167,7 @@ module Lutaml
162
167
  # re-materialize defaults that the post-run reset discards.
163
168
  attr_accessor :lutaml_constructor_seeded
164
169
 
165
- def initialize(attrs = {}, options = {})
170
+ def initialize(attrs = EMPTY_HASH, options = EMPTY_HASH)
166
171
  if lutaml_constructor_seeded
167
172
  # The deserialization constructor seeded constructor-equivalent
168
173
  # compiled state (defaults resolved, non-defaulted nil) and
@@ -13,39 +13,28 @@ module Lutaml
13
13
  Concurrent::Map.new
14
14
  end
15
15
 
16
- def initialize(rule, doc, format, attr, register, options,
16
+ # The extractor is pure stateless logic over its arguments; the
17
+ # per-call `new(*args).call` instance (Services::Base's default)
18
+ # allocated an object plus seven ivar writes per rule per element
19
+ # (~24k objects per 60 glossarist documents). The class-level call
20
+ # runs the same walk without the throwaway instance. The instance
21
+ # API is kept for compatibility.
22
+ def self.call(rule, doc, format, attr, register, _options,
17
23
  instance_object)
18
- super()
19
-
20
- @rule = rule
21
- @doc = doc
22
- @format = format
23
- @attr = attr
24
- @register = register
25
- @options = options
26
- @instance_object = instance_object
27
- end
24
+ rule_names = RULE_NAMES_CACHE[rule] ||=
25
+ rule.multiple_mappings? ? rule.name : [rule.name]
28
26
 
29
- def call
30
27
  rule_names.each do |rule_name|
31
- value = rule_value_for(rule_name)
28
+ value = rule_value_for(rule, doc, format, attr, register,
29
+ instance_object, rule_name)
32
30
  return value if Utils.initialized?(value)
33
31
  end
34
32
 
35
- uninitialized_value
36
- end
37
-
38
- private
39
-
40
- attr_reader :rule, :doc, :format, :attr, :register, :options,
41
- :instance_object
42
-
43
- def rule_names
44
- RULE_NAMES_CACHE[rule] ||=
45
- rule.multiple_mappings? ? rule.name : [rule.name]
33
+ Lutaml::Model::UninitializedClass.instance
46
34
  end
47
35
 
48
- def rule_value_for(name)
36
+ def self.rule_value_for(rule, doc, format, attr, register,
37
+ instance_object, name)
49
38
  # When name is nil but document is a hash-like object with a single key matching
50
39
  # the attribute name, extract that value. This handles the case where
51
40
  # map to: :content is used and the document is {"content": "value"}
@@ -58,31 +47,46 @@ instance_object)
58
47
  end
59
48
  end
60
49
 
61
- return doc if root_or_nil?(name)
50
+ return doc if name.nil? || rule.root_mapping?
62
51
  return convert_to_format(doc, format) if rule.raw_mapping?
63
- return fetch_value(name) if Utils.string_or_symbol_key?(doc, name)
52
+ return Utils.fetch_str_or_sym(doc, name) if Utils.string_or_symbol_key?(doc, name)
64
53
 
65
54
  if attr
66
55
  resolved = attr.default_value(register, instance_object)
67
56
  return resolved unless Utils.uninitialized?(resolved)
68
57
  end
69
58
 
70
- uninitialized_value
59
+ Lutaml::Model::UninitializedClass.instance
71
60
  end
72
61
 
73
- def root_or_nil?(name)
74
- name.nil? || rule.root_mapping?
62
+ def self.convert_to_format(doc, format)
63
+ adapter = Lutaml::Model::Config.adapter_for(format)
64
+ adapter.new(doc).public_send(:"to_#{format}")
75
65
  end
76
66
 
77
- def fetch_value(name)
78
- Utils.fetch_str_or_sym(doc, name)
67
+ def initialize(rule, doc, format, attr, register, options,
68
+ instance_object)
69
+ super()
70
+
71
+ @rule = rule
72
+ @doc = doc
73
+ @format = format
74
+ @attr = attr
75
+ @register = register
76
+ @options = options
77
+ @instance_object = instance_object
79
78
  end
80
79
 
81
- def convert_to_format(doc, format)
82
- adapter = Lutaml::Model::Config.adapter_for(format)
83
- adapter.new(doc).public_send(:"to_#{format}")
80
+ attr_reader :rule, :doc, :format, :attr, :register, :options,
81
+ :instance_object
82
+
83
+ def call
84
+ self.class.call(rule, doc, format, attr, register, options,
85
+ instance_object)
84
86
  end
85
87
 
88
+ private
89
+
86
90
  def uninitialized_value
87
91
  Lutaml::Model::UninitializedClass.instance
88
92
  end
@@ -172,7 +172,14 @@ module Lutaml
172
172
  # string_or_symbol_key?(hash, :key) # => true
173
173
  # string_or_symbol_key?(hash, "invalid_key") # => false
174
174
  def string_or_symbol_key?(hash, key)
175
- hash.key?(key.to_s) || hash.key?(key.to_sym)
175
+ if key.is_a?(String)
176
+ hash.key?(key) || hash.key?(key.to_sym)
177
+ elsif key.is_a?(Symbol)
178
+ # Same frozen-string probe as fetch_str_or_sym's Symbol branch.
179
+ hash.key?(key) || hash.key?(key.name)
180
+ else
181
+ hash.key?(key.to_s) || hash.key?(key.to_sym)
182
+ end
176
183
  end
177
184
 
178
185
  # Fetch the value from the hash using the key in string or symbol format
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lutaml
4
4
  module Model
5
- VERSION = "0.8.156"
5
+ VERSION = "0.8.158"
6
6
  end
7
7
  end
@@ -6,6 +6,10 @@ require "moxml/adapter/oga"
6
6
  module Lutaml
7
7
  module Xml
8
8
  module Adapter
9
+ # @deprecated the Oga engine is on the deprecation path — moxml's
10
+ # default engine (Nokogiri, or the leptris native engine when
11
+ # present) is the supported XML lane. Selection emits a
12
+ # deprecation warning; removal lands in a future release.
9
13
  class OgaAdapter < BaseAdapter
10
14
  MOXML_ADAPTER = Moxml::Adapter::Oga
11
15
  BUILDER_CLASS = Builder::Oga
@@ -7,6 +7,10 @@ require "moxml/adapter/rexml"
7
7
  module Lutaml
8
8
  module Xml
9
9
  module Adapter
10
+ # @deprecated the REXML engine is on the deprecation path — moxml's
11
+ # default engine (Nokogiri, or the leptris native engine when
12
+ # present) is the supported XML lane. Selection emits a
13
+ # deprecation warning; removal lands in a future release.
10
14
  class RexmlAdapter < BaseAdapter
11
15
  MOXML_ADAPTER = Moxml::Adapter::Rexml
12
16
  BUILDER_CLASS = Builder::Rexml