metaschema 0.2.1 → 0.2.3

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.
@@ -365,17 +365,23 @@ module Metaschema
365
365
  # Content mapping
366
366
  content = xml_map.instance_variable_get(:@content_mapping)
367
367
  if content
368
- lines << " map_content to: :#{content.to}"
368
+ opts = ["to: :#{content.to}"]
369
+ opts << "delegate: :#{content.delegate}" if content.delegate
370
+ lines << " map_content #{opts.join(', ')}"
369
371
  end
370
372
 
371
373
  # Attribute mappings
372
374
  xml_map.instance_variable_get(:@attributes)&.each do |xml_name, rule|
373
- lines << " map_attribute \"#{xml_name}\", to: :#{rule.to}"
375
+ opts = ["\"#{xml_name}\"", "to: :#{rule.to}"]
376
+ opts << "delegate: :#{rule.delegate}" if rule.delegate
377
+ lines << " map_attribute #{opts.join(', ')}"
374
378
  end
375
379
 
376
380
  # Element mappings
377
381
  xml_map.instance_variable_get(:@elements)&.each do |xml_name, rule|
378
- lines << " map_element \"#{xml_name}\", to: :#{rule.to}"
382
+ opts = ["\"#{xml_name}\"", "to: :#{rule.to}"]
383
+ opts << "delegate: :#{rule.delegate}" if rule.delegate
384
+ lines << " map_element #{opts.join(', ')}"
379
385
  end
380
386
 
381
387
  lines << " end"
@@ -390,17 +396,21 @@ module Metaschema
390
396
  end
391
397
  return nil unless kv_map
392
398
 
393
- mappings = kv_map.instance_variable_get(:@mappings)
394
- return nil unless mappings && !mappings.empty?
399
+ # lutaml-model 0.8.56+ stores key-value rules as per-key arrays
400
+ # (when_attribute partitions share a wire key); the public `mappings`
401
+ # reader returns the flattened rules.
402
+ mappings = kv_map.mappings
403
+ return nil if mappings.nil? || mappings.empty?
395
404
 
396
405
  lines = []
397
406
  lines << ""
398
407
  lines << " key_value do"
399
408
 
400
- root_name = kv_map.instance_variable_get(:@root_name)
409
+ root_name = kv_map.root_name
401
410
  lines << " root \"#{root_name}\"" if root_name && !root_name.empty?
402
411
 
403
- mappings.each do |json_name, rule|
412
+ mappings.each do |rule|
413
+ json_name = rule.name
404
414
  custom = rule.custom_methods
405
415
  if custom && (custom[:from] || custom[:to])
406
416
  opts = []
@@ -414,7 +424,7 @@ module Metaschema
414
424
  opts << opts_parts.join
415
425
  lines << " map \"#{json_name}\", #{opts.join(', ')}"
416
426
  else
417
- render_empty = rule.instance_variable_get(:@render_empty)
427
+ render_empty = rule.render_empty
418
428
  lines << if render_empty
419
429
  " map \"#{json_name}\", to: :#{rule.to}, render_empty: true"
420
430
  else
@@ -808,8 +818,9 @@ module Metaschema
808
818
  end
809
819
  return nil unless kv_map
810
820
 
811
- mappings = kv_map.instance_variable_get(:@mappings)
812
- mappings&.each do |json_name, rule|
821
+ mappings = kv_map.mappings
822
+ mappings&.each do |rule|
823
+ json_name = rule.name
813
824
  if rule.custom_methods[:to]&.to_s == method_name.to_s
814
825
  return json_name
815
826
  end
@@ -826,8 +837,9 @@ module Metaschema
826
837
  end
827
838
  return nil unless kv_map
828
839
 
829
- mappings = kv_map.instance_variable_get(:@mappings)
830
- mappings&.each do |json_name, rule|
840
+ mappings = kv_map.mappings
841
+ mappings&.each do |rule|
842
+ json_name = rule.name
831
843
  if rule.custom_methods[:from]&.to_s == method_name.to_s
832
844
  return json_name
833
845
  end
@@ -845,8 +857,8 @@ module Metaschema
845
857
  return nil unless kv_map
846
858
 
847
859
  ms = method_name.to_s
848
- mappings = kv_map.instance_variable_get(:@mappings)
849
- mappings&.each_value do |rule|
860
+ mappings = kv_map.mappings
861
+ mappings&.each do |rule|
850
862
  custom = rule.custom_methods
851
863
  if custom[:to]&.to_s == ms || custom[:from]&.to_s == ms
852
864
  return rule.to.to_s
@@ -21,21 +21,34 @@ module Metaschema
21
21
  "dateTime" => :date_time,
22
22
  "date-with-timezone" => :date,
23
23
  "date-time-with-timezone" => :date_time,
24
+ "day-time-duration" => :string,
24
25
 
25
26
  # String subtypes
26
27
  "uuid" => :string,
27
28
  "uri" => :string,
29
+ "uri-reference" => :string,
28
30
  "email" => :string,
31
+ "email-address" => :string,
29
32
  "hostname" => :string,
30
33
  "ip-address" => :string,
34
+ "ip-v4-address" => :string,
35
+ "ip-v6-address" => :string,
36
+ "base64" => :string,
31
37
 
32
38
  # Markup types — use Metaschema's own types
33
39
  "markup-line" => Metaschema::MarkupLineDatatype,
34
- "markup-multiline" => Metaschema::MarkupLineDatatype,
40
+ "markup-multiline" => Metaschema::MarkupMultilineDatatype,
35
41
  }.freeze
36
42
 
37
43
  MARKUP_TYPES = %w[markup-line markup-multiline].freeze
38
44
 
45
+ # Default JSON value key by data type. Determines the JSON property
46
+ # name that holds a field's content value when serialized.
47
+ JSON_VALUE_KEY = {
48
+ "markup-line" => "RICHTEXT",
49
+ "markup-multiline" => "prose",
50
+ }.freeze
51
+
39
52
  class << self
40
53
  def map(as_type)
41
54
  TYPE_MAP[as_type.to_s] || :string
@@ -49,6 +62,13 @@ module Metaschema
49
62
  as_type.to_s == "markup-multiline"
50
63
  end
51
64
 
65
+ # Returns the default JSON value key for the given data type.
66
+ # E.g. "markup-line" -> "RICHTEXT", "markup-multiline" -> "prose",
67
+ # everything else -> "STRVALUE".
68
+ def json_value_key(as_type)
69
+ JSON_VALUE_KEY[as_type.to_s] || "STRVALUE"
70
+ end
71
+
52
72
  # Register format-specific serializers for types that lutaml-model
53
73
  # doesn't handle correctly out of the box.
54
74
  def register_serializers!
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Metaschema
4
- VERSION = "0.2.1"
4
+ VERSION = "0.2.3"
5
5
  end
data/lib/metaschema.rb CHANGED
@@ -63,6 +63,7 @@ module Metaschema
63
63
  autoload :ListItemType, "metaschema/list_item_type"
64
64
  autoload :ListType, "metaschema/list_type"
65
65
  autoload :MarkupLineDatatype, "metaschema/markup_line_datatype"
66
+ autoload :MarkupMultilineDatatype, "metaschema/markup_multiline_datatype"
66
67
  autoload :MatchesConstraintType, "metaschema/matches_constraint_type"
67
68
  autoload :MetaschemaImportType, "metaschema/metaschema_import_type"
68
69
  autoload :MetaschemaConstraints, "metaschema/metaschema_constraints"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metaschema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
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-04-23 00:00:00.000000000 Z
11
+ date: 2026-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lutaml-model
@@ -16,16 +16,16 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.8.0
19
+ version: 0.8.114
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.8.0
26
+ version: 0.8.114
27
27
  - !ruby/object:Gem::Dependency
28
- name: tabulo
28
+ name: nokogiri
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: thor
42
+ name: tabulo
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.4'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.4'
55
69
  description: Parser and generator for NIST Metaschema
56
70
  email:
57
71
  - open.source@ribose.com'
@@ -117,11 +131,18 @@ files:
117
131
  - lib/metaschema/list_type.rb
118
132
  - lib/metaschema/markdown_doc_generator.rb
119
133
  - lib/metaschema/markup_line_datatype.rb
134
+ - lib/metaschema/markup_multiline_datatype.rb
120
135
  - lib/metaschema/matches_constraint_type.rb
121
136
  - lib/metaschema/metapath_evaluator.rb
122
137
  - lib/metaschema/metaschema_constraints.rb
123
138
  - lib/metaschema/metaschema_import_type.rb
124
139
  - lib/metaschema/model_generator.rb
140
+ - lib/metaschema/model_generator/assembly_factory.rb
141
+ - lib/metaschema/model_generator/field_factory.rb
142
+ - lib/metaschema/model_generator/services/collapsibles_collapser.rb
143
+ - lib/metaschema/model_generator/services/field_deserializer.rb
144
+ - lib/metaschema/model_generator/services/field_serializer.rb
145
+ - lib/metaschema/model_generator/utils.rb
125
146
  - lib/metaschema/namespace.rb
126
147
  - lib/metaschema/namespace_binding_type.rb
127
148
  - lib/metaschema/namespace_value.rb