lutaml-model 0.2.1 → 0.3.1
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/.gitignore +2 -0
- data/.rubocop.yml +7 -0
- data/.rubocop_todo.yml +207 -0
- data/Gemfile +6 -2
- data/README.adoc +1054 -126
- data/lib/lutaml/model/attribute.rb +4 -0
- data/lib/lutaml/model/error/invalid_value_error.rb +18 -0
- data/lib/lutaml/model/error.rb +8 -0
- data/lib/lutaml/model/key_value_mapping.rb +9 -1
- data/lib/lutaml/model/mapping_hash.rb +42 -0
- data/lib/lutaml/model/mapping_rule.rb +24 -2
- data/lib/lutaml/model/serialize.rb +270 -189
- data/lib/lutaml/model/toml_adapter/toml_rb_adapter.rb +2 -2
- data/lib/lutaml/model/type.rb +19 -13
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/model/xml_adapter/nokogiri_adapter.rb +104 -101
- data/lib/lutaml/model/xml_adapter/ox_adapter.rb +125 -85
- data/lib/lutaml/model/xml_adapter.rb +138 -7
- data/lib/lutaml/model/xml_mapping.rb +36 -6
- data/lib/lutaml/model/xml_mapping_rule.rb +6 -6
- data/lib/lutaml/model/yaml_adapter.rb +11 -3
- data/lib/lutaml/model.rb +7 -0
- metadata +6 -2
@@ -0,0 +1,18 @@
|
|
1
|
+
module Lutaml
|
2
|
+
module Model
|
3
|
+
class InvalidValueError < Error
|
4
|
+
def initialize(attr_name, value, allowed_values)
|
5
|
+
@attr_name = attr_name
|
6
|
+
@value = value
|
7
|
+
@allowed_values = allowed_values
|
8
|
+
|
9
|
+
super()
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
"#{@attr_name} is `#{@value}`, must be one of the " \
|
14
|
+
"following [#{@allowed_values.join(', ')}]"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -10,13 +10,21 @@ module Lutaml
|
|
10
10
|
@mappings = []
|
11
11
|
end
|
12
12
|
|
13
|
-
def map(
|
13
|
+
def map(
|
14
|
+
name,
|
15
|
+
to:,
|
16
|
+
render_nil: false,
|
17
|
+
with: {},
|
18
|
+
delegate: nil,
|
19
|
+
child_mappings: nil
|
20
|
+
)
|
14
21
|
@mappings << KeyValueMappingRule.new(
|
15
22
|
name,
|
16
23
|
to: to,
|
17
24
|
render_nil: render_nil,
|
18
25
|
with: with,
|
19
26
|
delegate: delegate,
|
27
|
+
child_mappings: child_mappings,
|
20
28
|
)
|
21
29
|
end
|
22
30
|
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# lib/lutaml/model/type.rb
|
2
|
+
|
3
|
+
module Lutaml
|
4
|
+
module Model
|
5
|
+
class MappingHash < Hash
|
6
|
+
attr_accessor :ordered
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@ordered = false
|
10
|
+
@item_order = []
|
11
|
+
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
def item_order
|
16
|
+
@item_order&.map { |key| normalize(key) } || keys
|
17
|
+
end
|
18
|
+
|
19
|
+
def item_order=(order)
|
20
|
+
raise "`item order` must be an array" unless order.is_a?(Array)
|
21
|
+
|
22
|
+
@item_order = order
|
23
|
+
end
|
24
|
+
|
25
|
+
def ordered?
|
26
|
+
@ordered
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def normalize(key)
|
32
|
+
if self[key.to_s]
|
33
|
+
key.to_s
|
34
|
+
elsif self[key.to_sym]
|
35
|
+
key.to_sym
|
36
|
+
else
|
37
|
+
key
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -2,14 +2,32 @@
|
|
2
2
|
module Lutaml
|
3
3
|
module Model
|
4
4
|
class MappingRule
|
5
|
-
attr_reader :name,
|
5
|
+
attr_reader :name,
|
6
|
+
:to,
|
7
|
+
:render_nil,
|
8
|
+
:custom_methods,
|
9
|
+
:delegate,
|
10
|
+
:mixed_content,
|
11
|
+
:child_mappings
|
6
12
|
|
7
|
-
def initialize(
|
13
|
+
def initialize(
|
14
|
+
name,
|
15
|
+
to:,
|
16
|
+
render_nil: false,
|
17
|
+
with: {},
|
18
|
+
delegate: nil,
|
19
|
+
mixed_content: false,
|
20
|
+
namespace_set: false,
|
21
|
+
child_mappings: nil
|
22
|
+
)
|
8
23
|
@name = name
|
9
24
|
@to = to
|
10
25
|
@render_nil = render_nil
|
11
26
|
@custom_methods = with
|
12
27
|
@delegate = delegate
|
28
|
+
@mixed_content = mixed_content
|
29
|
+
@namespace_set = namespace_set
|
30
|
+
@child_mappings = child_mappings
|
13
31
|
end
|
14
32
|
|
15
33
|
alias from name
|
@@ -38,6 +56,10 @@ module Lutaml
|
|
38
56
|
doc[name.to_s]
|
39
57
|
end
|
40
58
|
end
|
59
|
+
|
60
|
+
def namespace_set?
|
61
|
+
@namespace_set
|
62
|
+
end
|
41
63
|
end
|
42
64
|
end
|
43
65
|
end
|