lutaml-model 0.3.0 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +0 -5
- data/.rubocop_todo.yml +20 -101
- data/Gemfile +3 -18
- data/README.adoc +1100 -140
- data/lib/lutaml/model/attribute.rb +15 -2
- data/lib/lutaml/model/config.rb +0 -1
- data/lib/lutaml/model/error/invalid_value_error.rb +18 -0
- data/lib/lutaml/model/error.rb +8 -0
- data/lib/lutaml/model/json_adapter/json_document.rb +20 -0
- data/lib/lutaml/model/json_adapter/json_object.rb +28 -0
- data/lib/lutaml/model/json_adapter/{multi_json.rb → multi_json_adapter.rb} +2 -3
- data/lib/lutaml/model/json_adapter/{standard.rb → standard_json_adapter.rb} +2 -3
- data/lib/lutaml/model/json_adapter.rb +1 -31
- data/lib/lutaml/model/key_value_mapping.rb +9 -2
- data/lib/lutaml/model/key_value_mapping_rule.rb +0 -1
- data/lib/lutaml/model/mapping_hash.rb +0 -2
- data/lib/lutaml/model/mapping_rule.rb +5 -3
- data/lib/lutaml/model/schema/json_schema.rb +0 -1
- data/lib/lutaml/model/schema/relaxng_schema.rb +0 -1
- data/lib/lutaml/model/schema/xsd_schema.rb +0 -1
- data/lib/lutaml/model/schema/yaml_schema.rb +0 -1
- data/lib/lutaml/model/schema.rb +0 -1
- data/lib/lutaml/model/serializable.rb +0 -1
- data/lib/lutaml/model/serialize.rb +241 -153
- data/lib/lutaml/model/toml_adapter/toml_document.rb +20 -0
- data/lib/lutaml/model/toml_adapter/toml_object.rb +28 -0
- data/lib/lutaml/model/toml_adapter/toml_rb_adapter.rb +4 -5
- data/lib/lutaml/model/toml_adapter/tomlib_adapter.rb +2 -3
- data/lib/lutaml/model/toml_adapter.rb +0 -31
- data/lib/lutaml/model/type/date_time.rb +20 -0
- data/lib/lutaml/model/type/json.rb +34 -0
- data/lib/lutaml/model/type/time_without_date.rb +4 -3
- data/lib/lutaml/model/type.rb +61 -124
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/model/xml_adapter/nokogiri_adapter.rb +20 -13
- data/lib/lutaml/model/xml_adapter/oga_adapter.rb +4 -5
- data/lib/lutaml/model/xml_adapter/ox_adapter.rb +24 -17
- data/lib/lutaml/model/xml_adapter/xml_attribute.rb +27 -0
- data/lib/lutaml/model/xml_adapter/xml_document.rb +184 -0
- data/lib/lutaml/model/xml_adapter/xml_element.rb +94 -0
- data/lib/lutaml/model/xml_adapter/xml_namespace.rb +49 -0
- data/lib/lutaml/model/xml_adapter.rb +0 -266
- data/lib/lutaml/model/xml_mapping.rb +1 -1
- data/lib/lutaml/model/xml_mapping_rule.rb +3 -4
- data/lib/lutaml/model/yaml_adapter/standard_yaml_adapter.rb +34 -0
- data/lib/lutaml/model/yaml_adapter/yaml_document.rb +20 -0
- data/lib/lutaml/model/yaml_adapter/yaml_object.rb +28 -0
- data/lib/lutaml/model/yaml_adapter.rb +1 -19
- data/lib/lutaml/model.rb +7 -5
- metadata +19 -5
- data/lib/lutaml/model/xml_namespace.rb +0 -47
@@ -1,4 +1,3 @@
|
|
1
|
-
# lib/lutaml/model/attribute.rb
|
2
1
|
module Lutaml
|
3
2
|
module Model
|
4
3
|
class Attribute
|
@@ -6,7 +5,8 @@ module Lutaml
|
|
6
5
|
|
7
6
|
def initialize(name, type, options = {})
|
8
7
|
@name = name
|
9
|
-
@type = type
|
8
|
+
@type = cast_type(type)
|
9
|
+
|
10
10
|
@options = options
|
11
11
|
|
12
12
|
if collection? && !options[:default]
|
@@ -14,6 +14,19 @@ module Lutaml
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
def cast_type(type)
|
18
|
+
case type
|
19
|
+
when Class
|
20
|
+
type
|
21
|
+
when String
|
22
|
+
Type.const_get(type)
|
23
|
+
when Symbol
|
24
|
+
Type.const_get(type.to_s.split("_").collect(&:capitalize).join)
|
25
|
+
end
|
26
|
+
rescue NameError
|
27
|
+
raise ArgumentError, "Unknown Lutaml::Model::Type: #{type}"
|
28
|
+
end
|
29
|
+
|
17
30
|
def collection?
|
18
31
|
options[:collection] || false
|
19
32
|
end
|
data/lib/lutaml/model/config.rb
CHANGED
@@ -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
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "json_object"
|
4
|
+
|
5
|
+
module Lutaml
|
6
|
+
module Model
|
7
|
+
module JsonAdapter
|
8
|
+
# Base class for JSON documents
|
9
|
+
class JsonDocument < JsonObject
|
10
|
+
def self.parse(json)
|
11
|
+
raise NotImplementedError, "Subclasses must implement `parse`."
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_json(*args)
|
15
|
+
raise NotImplementedError, "Subclasses must implement `to_json`."
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lutaml
|
4
|
+
module Model
|
5
|
+
module JsonAdapter
|
6
|
+
# Base class for JSON objects
|
7
|
+
class JsonObject
|
8
|
+
attr_reader :attributes
|
9
|
+
|
10
|
+
def initialize(attributes = {})
|
11
|
+
@attributes = attributes
|
12
|
+
end
|
13
|
+
|
14
|
+
def [](key)
|
15
|
+
@attributes[key]
|
16
|
+
end
|
17
|
+
|
18
|
+
def []=(key, value)
|
19
|
+
@attributes[key] = value
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_h
|
23
|
+
@attributes
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,11 +1,10 @@
|
|
1
|
-
# lib/lutaml/model/json_adapter/multi_json.rb
|
2
1
|
require "multi_json"
|
3
|
-
require_relative "
|
2
|
+
require_relative "json_document"
|
4
3
|
|
5
4
|
module Lutaml
|
6
5
|
module Model
|
7
6
|
module JsonAdapter
|
8
|
-
class
|
7
|
+
class MultiJsonAdapter < JsonDocument
|
9
8
|
def self.parse(json)
|
10
9
|
data = MultiJson.load(json)
|
11
10
|
new(data)
|
@@ -1,11 +1,10 @@
|
|
1
|
-
# lib/lutaml/model/json_adapter/standard.rb
|
2
1
|
require "json"
|
3
|
-
require_relative "
|
2
|
+
require_relative "json_document"
|
4
3
|
|
5
4
|
module Lutaml
|
6
5
|
module Model
|
7
6
|
module JsonAdapter
|
8
|
-
class
|
7
|
+
class StandardJsonAdapter < JsonDocument
|
9
8
|
def self.parse(json)
|
10
9
|
attributes = JSON.parse(json, create_additions: false)
|
11
10
|
new(attributes)
|
@@ -1,38 +1,8 @@
|
|
1
|
-
#
|
2
|
-
require "json"
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
3
|
module Lutaml
|
5
4
|
module Model
|
6
5
|
module JsonAdapter
|
7
|
-
class JsonObject
|
8
|
-
attr_reader :attributes
|
9
|
-
|
10
|
-
def initialize(attributes = {})
|
11
|
-
@attributes = attributes
|
12
|
-
end
|
13
|
-
|
14
|
-
def [](key)
|
15
|
-
@attributes[key]
|
16
|
-
end
|
17
|
-
|
18
|
-
def []=(key, value)
|
19
|
-
@attributes[key] = value
|
20
|
-
end
|
21
|
-
|
22
|
-
def to_h
|
23
|
-
@attributes
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
class Document < JsonObject
|
28
|
-
def self.parse(json)
|
29
|
-
raise NotImplementedError, "Subclasses must implement `parse`."
|
30
|
-
end
|
31
|
-
|
32
|
-
def to_json(*args)
|
33
|
-
raise NotImplementedError, "Subclasses must implement `to_json`."
|
34
|
-
end
|
35
|
-
end
|
36
6
|
end
|
37
7
|
end
|
38
8
|
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
# lib/lutaml/model/key_value_mapping.rb
|
2
1
|
require_relative "key_value_mapping_rule"
|
3
2
|
|
4
3
|
module Lutaml
|
@@ -10,13 +9,21 @@ module Lutaml
|
|
10
9
|
@mappings = []
|
11
10
|
end
|
12
11
|
|
13
|
-
def map(
|
12
|
+
def map(
|
13
|
+
name,
|
14
|
+
to:,
|
15
|
+
render_nil: false,
|
16
|
+
with: {},
|
17
|
+
delegate: nil,
|
18
|
+
child_mappings: nil
|
19
|
+
)
|
14
20
|
@mappings << KeyValueMappingRule.new(
|
15
21
|
name,
|
16
22
|
to: to,
|
17
23
|
render_nil: render_nil,
|
18
24
|
with: with,
|
19
25
|
delegate: delegate,
|
26
|
+
child_mappings: child_mappings,
|
20
27
|
)
|
21
28
|
end
|
22
29
|
|
@@ -1,4 +1,3 @@
|
|
1
|
-
# lib/lutaml/model/mapping_rule.rb
|
2
1
|
module Lutaml
|
3
2
|
module Model
|
4
3
|
class MappingRule
|
@@ -7,7 +6,8 @@ module Lutaml
|
|
7
6
|
:render_nil,
|
8
7
|
:custom_methods,
|
9
8
|
:delegate,
|
10
|
-
:mixed_content
|
9
|
+
:mixed_content,
|
10
|
+
:child_mappings
|
11
11
|
|
12
12
|
def initialize(
|
13
13
|
name,
|
@@ -16,7 +16,8 @@ module Lutaml
|
|
16
16
|
with: {},
|
17
17
|
delegate: nil,
|
18
18
|
mixed_content: false,
|
19
|
-
namespace_set: false
|
19
|
+
namespace_set: false,
|
20
|
+
child_mappings: nil
|
20
21
|
)
|
21
22
|
@name = name
|
22
23
|
@to = to
|
@@ -25,6 +26,7 @@ module Lutaml
|
|
25
26
|
@delegate = delegate
|
26
27
|
@mixed_content = mixed_content
|
27
28
|
@namespace_set = namespace_set
|
29
|
+
@child_mappings = child_mappings
|
28
30
|
end
|
29
31
|
|
30
32
|
alias from name
|
data/lib/lutaml/model/schema.rb
CHANGED