lutaml-model 0.3.24 → 0.3.26

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +36 -17
  3. data/README.adoc +396 -30
  4. data/lib/lutaml/model/attribute.rb +52 -27
  5. data/lib/lutaml/model/error/pattern_not_matched_error.rb +17 -0
  6. data/lib/lutaml/model/error/type_error.rb +9 -0
  7. data/lib/lutaml/model/error/unknown_type_error.rb +9 -0
  8. data/lib/lutaml/model/error/validation_error.rb +0 -1
  9. data/lib/lutaml/model/error.rb +3 -0
  10. data/lib/lutaml/model/mapping_hash.rb +8 -0
  11. data/lib/lutaml/model/serialize.rb +10 -5
  12. data/lib/lutaml/model/type/boolean.rb +38 -0
  13. data/lib/lutaml/model/type/date.rb +35 -0
  14. data/lib/lutaml/model/type/date_time.rb +32 -4
  15. data/lib/lutaml/model/type/decimal.rb +42 -0
  16. data/lib/lutaml/model/type/float.rb +37 -0
  17. data/lib/lutaml/model/type/hash.rb +62 -0
  18. data/lib/lutaml/model/type/integer.rb +41 -0
  19. data/lib/lutaml/model/type/string.rb +49 -0
  20. data/lib/lutaml/model/type/time.rb +49 -0
  21. data/lib/lutaml/model/type/time_without_date.rb +37 -5
  22. data/lib/lutaml/model/type/value.rb +52 -0
  23. data/lib/lutaml/model/type.rb +50 -114
  24. data/lib/lutaml/model/validation.rb +2 -1
  25. data/lib/lutaml/model/version.rb +1 -1
  26. data/lib/lutaml/model/xml_adapter/builder/nokogiri.rb +12 -3
  27. data/lib/lutaml/model/xml_adapter/builder/ox.rb +7 -1
  28. data/lib/lutaml/model/xml_adapter/nokogiri_adapter.rb +3 -1
  29. data/lib/lutaml/model/xml_adapter/ox_adapter.rb +12 -8
  30. data/lib/lutaml/model/xml_adapter/xml_document.rb +6 -8
  31. data/lib/lutaml/model/xml_mapping.rb +6 -2
  32. data/lib/lutaml/model/xml_mapping_rule.rb +7 -1
  33. data/lutaml-model.gemspec +1 -1
  34. data/spec/address_spec.rb +170 -0
  35. data/spec/fixtures/address.rb +33 -0
  36. data/spec/fixtures/person.rb +73 -0
  37. data/spec/fixtures/sample_model.rb +40 -0
  38. data/spec/fixtures/vase.rb +38 -0
  39. data/spec/fixtures/xml/special_char.xml +13 -0
  40. data/spec/lutaml/model/attribute_spec.rb +139 -0
  41. data/spec/lutaml/model/cdata_spec.rb +520 -0
  42. data/spec/lutaml/model/collection_spec.rb +299 -0
  43. data/spec/lutaml/model/comparable_model_spec.rb +106 -0
  44. data/spec/lutaml/model/custom_model_spec.rb +410 -0
  45. data/spec/lutaml/model/custom_serialization_spec.rb +170 -0
  46. data/spec/lutaml/model/defaults_spec.rb +221 -0
  47. data/spec/lutaml/model/delegation_spec.rb +340 -0
  48. data/spec/lutaml/model/inheritance_spec.rb +92 -0
  49. data/spec/lutaml/model/json_adapter_spec.rb +37 -0
  50. data/spec/lutaml/model/key_value_mapping_spec.rb +86 -0
  51. data/spec/lutaml/model/map_content_spec.rb +118 -0
  52. data/spec/lutaml/model/mixed_content_spec.rb +625 -0
  53. data/spec/lutaml/model/namespace_spec.rb +57 -0
  54. data/spec/lutaml/model/ordered_content_spec.rb +83 -0
  55. data/spec/lutaml/model/render_nil_spec.rb +138 -0
  56. data/spec/lutaml/model/schema/json_schema_spec.rb +79 -0
  57. data/spec/lutaml/model/schema/relaxng_schema_spec.rb +60 -0
  58. data/spec/lutaml/model/schema/xsd_schema_spec.rb +55 -0
  59. data/spec/lutaml/model/schema/yaml_schema_spec.rb +47 -0
  60. data/spec/lutaml/model/serializable_spec.rb +297 -0
  61. data/spec/lutaml/model/serializable_validation_spec.rb +90 -0
  62. data/spec/lutaml/model/simple_model_spec.rb +314 -0
  63. data/spec/lutaml/model/toml_adapter_spec.rb +39 -0
  64. data/spec/lutaml/model/type/boolean_spec.rb +54 -0
  65. data/spec/lutaml/model/type/date_spec.rb +118 -0
  66. data/spec/lutaml/model/type/date_time_spec.rb +127 -0
  67. data/spec/lutaml/model/type/decimal_spec.rb +125 -0
  68. data/spec/lutaml/model/type/float_spec.rb +191 -0
  69. data/spec/lutaml/model/type/hash_spec.rb +63 -0
  70. data/spec/lutaml/model/type/integer_spec.rb +145 -0
  71. data/spec/lutaml/model/type/string_spec.rb +150 -0
  72. data/spec/lutaml/model/type/time_spec.rb +142 -0
  73. data/spec/lutaml/model/type/time_without_date_spec.rb +125 -0
  74. data/spec/lutaml/model/type_spec.rb +276 -0
  75. data/spec/lutaml/model/utils_spec.rb +79 -0
  76. data/spec/lutaml/model/validation_spec.rb +83 -0
  77. data/spec/lutaml/model/with_child_mapping_spec.rb +174 -0
  78. data/spec/lutaml/model/xml_adapter/nokogiri_adapter_spec.rb +56 -0
  79. data/spec/lutaml/model/xml_adapter/oga_adapter_spec.rb +56 -0
  80. data/spec/lutaml/model/xml_adapter/ox_adapter_spec.rb +61 -0
  81. data/spec/lutaml/model/xml_adapter/xml_namespace_spec.rb +251 -0
  82. data/spec/lutaml/model/xml_adapter_spec.rb +178 -0
  83. data/spec/lutaml/model/xml_mapping_spec.rb +863 -0
  84. data/spec/lutaml/model/yaml_adapter_spec.rb +30 -0
  85. data/spec/lutaml/model_spec.rb +1 -0
  86. data/spec/person_spec.rb +161 -0
  87. data/spec/spec_helper.rb +33 -0
  88. metadata +68 -2
@@ -1,16 +1,48 @@
1
+ require "time"
2
+
1
3
  module Lutaml
2
4
  module Model
3
5
  module Type
4
- # Time representation without date
5
- class TimeWithoutDate
6
+ class TimeWithoutDate < Value
7
+ # TODO: we probably want to do something like this because using
8
+ # Time.parse will set the date to today.
9
+ #
10
+ # time = ::Time.parse(value.to_s)
11
+ # ::Time.new(1, 1, 1, time.hour, time.min, time.sec)
12
+
6
13
  def self.cast(value)
7
- return if value.nil?
14
+ return nil if value.nil?
8
15
 
9
- ::Time.parse(value.to_s)
16
+ case value
17
+ when ::Time then value
18
+ else ::Time.parse(value.to_s)
19
+ end
20
+ rescue ArgumentError
21
+ nil
10
22
  end
11
23
 
12
24
  def self.serialize(value)
13
- value.strftime("%H:%M:%S")
25
+ return nil if value.nil?
26
+
27
+ value = cast(value)
28
+ value.strftime("%H:%M:%S") # Format as HH:MM:SS
29
+ end
30
+
31
+ # Instance methods for format-specific serialization
32
+ def to_xml
33
+ self.class.serialize(value)
34
+ end
35
+
36
+ def to_json(*_args)
37
+ self.class.serialize(value)
38
+ end
39
+
40
+ def to_yaml
41
+ self.class.serialize(value)
42
+ end
43
+
44
+ def to_toml
45
+ value.strftime("%H:%M:%S.%L") # Include milliseconds for TOML
14
46
  end
15
47
  end
16
48
  end
@@ -0,0 +1,52 @@
1
+ require_relative "../config"
2
+
3
+ module Lutaml
4
+ module Model
5
+ module Type
6
+ # Base class for all value types
7
+ class Value
8
+ attr_reader :value
9
+
10
+ def initialize(value)
11
+ @value = self.class.cast(value)
12
+ end
13
+
14
+ def self.cast(value)
15
+ return nil if value.nil?
16
+
17
+ value
18
+ end
19
+
20
+ def self.serialize(value)
21
+ return nil if value.nil?
22
+
23
+ new(value).to_s
24
+ end
25
+
26
+ # Instance methods for serialization
27
+ def to_s
28
+ value.to_s
29
+ end
30
+
31
+ # Format-specific instance methods
32
+ ::Lutaml::Model::Config::AVAILABLE_FORMATS.each do |format|
33
+ define_method(:"to_#{format}") do
34
+ value
35
+ end
36
+ end
37
+
38
+ # Class-level format conversion
39
+ def self.from_format(value, format)
40
+ new(send(:"from_#{format}", value))
41
+ end
42
+
43
+ # Default format-specific class methods that can be overridden
44
+ ::Lutaml::Model::Config::AVAILABLE_FORMATS.each do |format|
45
+ define_singleton_method(:"from_#{format}") do |value|
46
+ cast(value)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -1,136 +1,72 @@
1
- require "date"
2
- require "bigdecimal"
3
-
4
1
  module Lutaml
5
2
  module Model
6
3
  module Type
7
- # This module provides a set of methods to cast and serialize values
8
-
9
- # TODO: Make Boolean a separate class
10
-
11
- %w(
12
- String
13
- Integer
14
- Float
15
- Date
16
- Time
17
- Boolean
18
- Decimal
19
- Hash
20
- ).each do |t|
21
- class_eval <<~HEREDOC, __FILE__, __LINE__ + 1
22
- class #{t} # class Integer
23
- def self.cast(value) # def self.cast(value)
24
- return if value.nil? # return if value.nil?
25
- #
26
- Type.cast(value, #{t}) # Type.cast(value, Integer)
27
- end # end
28
-
29
- def self.serialize(value) # def self.serialize(value)
30
- return if value.nil? # return if value.nil?
31
- #
32
- Type.serialize(value, #{t}) # Type.serialize(value, Integer)
33
- end # end
34
- end # end
35
- HEREDOC
36
- end
37
-
38
- UUID_REGEX = /\A[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\z/
39
-
40
- def self.cast(value, type)
41
- return if value.nil?
42
-
43
- case type.to_s.split("::").last
44
- when "String"
45
- value.to_s
46
- when "Integer"
47
- value.to_i
48
- when "Float"
49
- value.to_f
50
- when "Date"
51
- begin
52
- ::Date.parse(value.to_s)
53
- rescue ArgumentError
54
- nil
55
- end
56
- when "DateTime"
57
- DateTime.cast(value)
58
- when "Time"
59
- ::Time.parse(value.to_s)
60
- when "TimeWithoutDate"
61
- TimeWithoutDate.cast(value)
62
- when "Boolean"
63
- to_boolean(value)
64
- when "Decimal"
65
- unless defined?(BigDecimal)
66
- raise Lutaml::Model::TypeNotEnabledError.new("Decimal", value)
4
+ TYPE_CODES = {
5
+ string: "Lutaml::Model::Type::String",
6
+ integer: "Lutaml::Model::Type::Integer",
7
+ float: "Lutaml::Model::Type::Float",
8
+ decimal: "Lutaml::Model::Type::Decimal",
9
+ date: "Lutaml::Model::Type::Date",
10
+ time: "Lutaml::Model::Type::Time",
11
+ date_time: "Lutaml::Model::Type::DateTime",
12
+ time_without_date: "Lutaml::Model::Type::TimeWithoutDate",
13
+ boolean: "Lutaml::Model::Type::Boolean",
14
+ hash: "Lutaml::Model::Type::Hash",
15
+ }.freeze
16
+
17
+ class << self
18
+ def register_builtin_types
19
+ TYPE_CODES.each do |type_name, type_class|
20
+ register(type_name, const_get(type_class))
67
21
  end
68
-
69
- BigDecimal(value.to_s)
70
- when "Hash"
71
- normalize_hash(Hash(value))
72
- else
73
- value
74
22
  end
75
- end
76
-
77
- def self.serialize(value, type)
78
- return if value.nil?
79
23
 
80
- case type.to_s.split("::").last
81
- when "Date"
82
- value.iso8601
83
- when "DateTime"
84
- DateTime.serialize(value)
85
- when "Integer"
86
- value.to_i
87
- when "Float"
88
- value.to_f
89
- when "Boolean"
90
- to_boolean(value)
91
- when "Decimal"
92
- unless defined?(BigDecimal)
93
- raise Lutaml::Model::TypeNotEnabledError.new("Decimal", value)
24
+ def register(type_name, type_class)
25
+ unless type_class < Value
26
+ raise TypeError,
27
+ "class '#{type_class}' is not a valid Lutaml::Model::Type::Value"
94
28
  end
95
29
 
96
- value.to_s("F")
97
- when "Hash"
98
- Hash(value)
99
- else
100
- value.to_s
30
+ @registry ||= {}
31
+ @registry[type_name.to_sym] = type_class
101
32
  end
102
- end
103
33
 
104
- def self.to_boolean(value)
105
- if value == true || value.to_s =~ (/^(true|t|yes|y|1)$/i)
106
- return true
107
- end
34
+ def lookup(type_name)
35
+ @registry ||= {}
36
+ klass = @registry[type_name.to_sym]
108
37
 
109
- if value == false || value.nil? || value.to_s =~ (/^(false|f|no|n|0)$/i)
110
- return false
111
- end
38
+ raise UnknownTypeError.new(type_name) unless klass
112
39
 
113
- raise ArgumentError.new("invalid value for Boolean: \"#{value}\"")
114
- end
40
+ klass
41
+ end
115
42
 
116
- def self.normalize_hash(hash)
117
- return hash["text"] if hash.keys == ["text"]
43
+ def cast(value, type)
44
+ return nil if value.nil?
118
45
 
119
- hash = hash.to_h if hash.is_a?(Lutaml::Model::MappingHash)
46
+ type.cast(value)
47
+ end
120
48
 
121
- hash.filter_map do |key, value|
122
- next if key == "text"
49
+ def serialize(value, type)
50
+ return nil if value.nil?
123
51
 
124
- if value.is_a?(::Hash)
125
- [key, normalize_hash(value)]
126
- else
127
- [key, value]
128
- end
129
- end.to_h
52
+ type.serialize(value)
53
+ end
130
54
  end
131
55
  end
132
56
  end
133
57
  end
134
58
 
135
- require_relative "type/time_without_date"
59
+ # Register built-in types
60
+ require_relative "type/value"
61
+ require_relative "type/string"
62
+ require_relative "type/integer"
63
+ require_relative "type/float"
64
+ require_relative "type/date"
65
+ require_relative "type/time"
136
66
  require_relative "type/date_time"
67
+ require_relative "type/time_without_date"
68
+ require_relative "type/boolean"
69
+ require_relative "type/decimal"
70
+ require_relative "type/hash"
71
+
72
+ Lutaml::Model::Type.register_builtin_types
@@ -8,7 +8,8 @@ module Lutaml
8
8
  begin
9
9
  attr.validate_value!(value)
10
10
  rescue Lutaml::Model::InvalidValueError,
11
- Lutaml::Model::CollectionCountOutOfRangeError => e
11
+ Lutaml::Model::CollectionCountOutOfRangeError,
12
+ PatternNotMatchedError => e
12
13
  errors << e
13
14
  end
14
15
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lutaml
4
4
  module Model
5
- VERSION = "0.3.24"
5
+ VERSION = "0.3.26"
6
6
  end
7
7
  end
@@ -39,6 +39,8 @@ module Lutaml
39
39
  )
40
40
  add_namespace_prefix(prefix)
41
41
 
42
+ element_name = "#{element_name}_" if respond_to?(element_name)
43
+
42
44
  if block_given?
43
45
  public_send(element_name, attributes) do
44
46
  xml.parent.namespace = nil if prefix.nil? && !prefix_unset
@@ -49,12 +51,19 @@ module Lutaml
49
51
  end
50
52
  end
51
53
 
52
- def add_text(element, text)
54
+ def add_text(element, text, cdata: false)
55
+ return add_cdata(element, text) if cdata
56
+
53
57
  if element.is_a?(self.class)
54
58
  element = element.xml.parent
55
59
  end
56
60
 
57
- element << text.to_s
61
+ text_node = ::Nokogiri::XML::Text.new(text.to_s, element)
62
+ element.add_child(text_node)
63
+ end
64
+
65
+ def add_cdata(element, value)
66
+ element.cdata(value)
58
67
  end
59
68
 
60
69
  def add_namespace_prefix(prefix)
@@ -64,7 +73,7 @@ module Lutaml
64
73
  end
65
74
 
66
75
  def method_missing(method_name, *args, &block)
67
- if block
76
+ if block_given?
68
77
  xml.public_send(method_name, *args, &block)
69
78
  else
70
79
  xml.public_send(method_name, *args)
@@ -66,10 +66,16 @@ module Lutaml
66
66
  xml.text(text)
67
67
  end
68
68
 
69
- def add_text(element, text)
69
+ def add_text(element, text, cdata: false)
70
+ return element.cdata(text) if cdata
71
+
70
72
  element << text
71
73
  end
72
74
 
75
+ def add_cdata(element, value)
76
+ element.cdata(value)
77
+ end
78
+
73
79
  # Add XML namespace to document
74
80
  #
75
81
  # Ox doesn't support XML namespaces so we only save the
@@ -74,10 +74,12 @@ module Lutaml
74
74
  value = attribute_value_for(element, element_rule)
75
75
 
76
76
  if element_rule == xml_mapping.content_mapping
77
+ next if element_rule.cdata && name == "text"
78
+
77
79
  text = xml_mapping.content_mapping.serialize(element)
78
80
  text = text[curr_index] if text.is_a?(Array)
79
81
 
80
- next prefixed_xml.text(text) if element.mixed?
82
+ next prefixed_xml.add_text(xml, text, cdata: element_rule.cdata) if element.mixed?
81
83
 
82
84
  content << text
83
85
  elsif !value.nil? || element_rule.render_nil?
@@ -14,6 +14,7 @@ module Lutaml
14
14
 
15
15
  def to_xml(options = {})
16
16
  builder = Builder::Ox.build
17
+ builder.xml.instruct(:xml, encoding: options[:encoding] || "UTF-8", version: options[:version])
17
18
 
18
19
  if @root.is_a?(Lutaml::Model::XmlAdapter::OxElement)
19
20
  @root.build_xml(builder)
@@ -26,7 +27,7 @@ module Lutaml
26
27
  end
27
28
 
28
29
  xml_data = builder.xml.to_s
29
- options[:declaration] ? declaration(options) + xml_data : xml_data
30
+ options[:declaration] ? xml_data : xml_data.sub(/\A<\?xml[^>]*\?>\n?/, "")
30
31
  end
31
32
 
32
33
  private
@@ -55,15 +56,15 @@ module Lutaml
55
56
  mapper_class: mapper_class)
56
57
  value = attribute_value_for(element, element_rule)
57
58
 
59
+ next if element_rule == xml_mapping.content_mapping && element_rule.cdata && name == "text"
60
+
58
61
  if element_rule == xml_mapping.content_mapping
59
62
  text = element.send(xml_mapping.content_mapping.to)
60
63
  text = text[curr_index] if text.is_a?(Array)
61
64
 
62
- if element.mixed?
63
- el.add_text(el, text)
64
- else
65
- content << text
66
- end
65
+ next el.add_text(el, text, cdata: element_rule.cdata) if element.mixed?
66
+
67
+ content << text
67
68
  elsif !value.nil? || element_rule.render_nil?
68
69
  value = value[curr_index] if attribute_def.collection?
69
70
 
@@ -87,10 +88,13 @@ module Lutaml
87
88
 
88
89
  class OxElement < XmlElement
89
90
  def initialize(node, root_node: nil)
90
- if node.is_a?(String)
91
+ case node
92
+ when String
91
93
  super("text", {}, [], node, parent_document: root_node)
92
- elsif node.is_a?(Ox::Comment)
94
+ when Ox::Comment
93
95
  super("comment", {}, [], node.value, parent_document: root_node)
96
+ when Ox::CData
97
+ super("#cdata-section", {}, [], node.value, parent_document: root_node)
94
98
  else
95
99
  namespace_attributes(node.attributes).each do |(name, value)|
96
100
  if root_node
@@ -84,8 +84,6 @@ module Lutaml
84
84
 
85
85
  value = if child.text?
86
86
  child.text
87
- elsif attr&.raw?
88
- child.children.map(&:to_xml).join
89
87
  else
90
88
  parse_element(child, attr&.type || klass, format)
91
89
  end
@@ -154,16 +152,16 @@ module Lutaml
154
152
  )
155
153
  elsif rule.prefix_set?
156
154
  xml.create_and_add_element(rule.name, prefix: prefix) do
157
- add_value(xml, value, attribute)
155
+ add_value(xml, value, attribute, cdata: rule.cdata)
158
156
  end
159
157
  else
160
158
  xml.create_and_add_element(rule.name) do
161
- add_value(xml, value, attribute)
159
+ add_value(xml, value, attribute, cdata: rule.cdata)
162
160
  end
163
161
  end
164
162
  end
165
163
 
166
- def add_value(xml, value, attribute)
164
+ def add_value(xml, value, attribute, cdata: false)
167
165
  if !value.nil?
168
166
  serialized_value = attribute.type.serialize(value)
169
167
 
@@ -174,7 +172,7 @@ module Lutaml
174
172
  end
175
173
  end
176
174
  else
177
- xml.add_text(xml, serialized_value)
175
+ xml.add_text(xml, serialized_value, cdata: cdata)
178
176
  end
179
177
  end
180
178
  end
@@ -246,7 +244,7 @@ module Lutaml
246
244
  value = attribute_value_for(element, rule)
247
245
  return unless render_element?(rule, element, value)
248
246
 
249
- xml.add_text(xml, value)
247
+ xml.add_text(xml, value, cdata: rule.cdata)
250
248
  end
251
249
 
252
250
  def process_content_mapping(element, content_rule, xml)
@@ -263,7 +261,7 @@ module Lutaml
263
261
  text = content_rule.serialize(element)
264
262
  text = text.join if text.is_a?(Array)
265
263
 
266
- xml.add_text(xml, text)
264
+ xml.add_text(xml, text, cdata: content_rule.cdata)
267
265
  end
268
266
  end
269
267
 
@@ -47,6 +47,7 @@ module Lutaml
47
47
  render_default: false,
48
48
  with: {},
49
49
  delegate: nil,
50
+ cdata: false,
50
51
  namespace: (namespace_set = false
51
52
  nil),
52
53
  prefix: (prefix_set = false
@@ -61,6 +62,7 @@ module Lutaml
61
62
  render_default: render_default,
62
63
  with: with,
63
64
  delegate: delegate,
65
+ cdata: cdata,
64
66
  namespace: namespace,
65
67
  default_namespace: namespace_uri,
66
68
  prefix: prefix,
@@ -109,7 +111,8 @@ module Lutaml
109
111
  render_default: false,
110
112
  with: {},
111
113
  delegate: nil,
112
- mixed: false
114
+ mixed: false,
115
+ cdata: false
113
116
  )
114
117
  validate!("content", to, with)
115
118
 
@@ -121,6 +124,7 @@ module Lutaml
121
124
  with: with,
122
125
  delegate: delegate,
123
126
  mixed_content: mixed,
127
+ cdata: cdata,
124
128
  )
125
129
  end
126
130
 
@@ -211,7 +215,7 @@ module Lutaml
211
215
  end
212
216
 
213
217
  def find_by_name(name)
214
- if name.to_s == "text"
218
+ if ["text", "#cdata-section"].include?(name.to_s)
215
219
  content_mapping
216
220
  else
217
221
  mappings.detect do |rule|
@@ -3,7 +3,7 @@ require_relative "mapping_rule"
3
3
  module Lutaml
4
4
  module Model
5
5
  class XmlMappingRule < MappingRule
6
- attr_reader :namespace, :prefix, :mixed_content, :default_namespace
6
+ attr_reader :namespace, :prefix, :mixed_content, :default_namespace, :cdata
7
7
 
8
8
  def initialize(
9
9
  name,
@@ -15,6 +15,7 @@ module Lutaml
15
15
  namespace: nil,
16
16
  prefix: nil,
17
17
  mixed_content: false,
18
+ cdata: false,
18
19
  namespace_set: false,
19
20
  prefix_set: false,
20
21
  attribute: false,
@@ -38,6 +39,7 @@ module Lutaml
38
39
  end
39
40
  @prefix = prefix
40
41
  @mixed_content = mixed_content
42
+ @cdata = cdata
41
43
 
42
44
  @default_namespace = default_namespace
43
45
 
@@ -61,6 +63,10 @@ module Lutaml
61
63
  name == "__raw_mapping"
62
64
  end
63
65
 
66
+ def content_key
67
+ cdata ? "#cdata-section" : "text"
68
+ end
69
+
64
70
  def mixed_content?
65
71
  !!@mixed_content
66
72
  end
data/lutaml-model.gemspec CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
  # RubyGem that have been added into git.
26
26
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
27
27
  `git ls-files -z`.split("\x0").reject do |f|
28
- f.match(%r{^(test|spec|features)/})
28
+ f.match(%r{^(test|features)/})
29
29
  end
30
30
  end
31
31
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }