lutaml-model 0.3.1 → 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 +109 -6
- data/lib/lutaml/model/attribute.rb +15 -2
- data/lib/lutaml/model/config.rb +0 -1
- 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 +0 -1
- 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 +0 -1
- 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 +22 -4
- 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 +2 -3
- 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 +5 -6
- data/lib/lutaml/model/xml_adapter/oga_adapter.rb +4 -5
- data/lib/lutaml/model/xml_adapter/ox_adapter.rb +8 -9
- 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 -285
- 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 -27
- data/lib/lutaml/model.rb +0 -5
- metadata +17 -5
- data/lib/lutaml/model/xml_namespace.rb +0 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9a3608f755616317667038ebd8f71368c23dcf935a7b07ad33d8efd1fa1df23
|
4
|
+
data.tar.gz: 9a69a3a03c401fa4a0eff423315dc979e4f5b87c28b28bf4b4d10b7f118b6a77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 612d55df7ef46e1266b6d6e2fa4a6e451862252895a8f8b66b0a1f42bb96d289fc28c160ee1e2d609bc4ebc4ce8db00d14a1fca3061e8465a2f867403f5672b0
|
7
|
+
data.tar.gz: 20235f85e8719fceb5a048dfcebf9f80e0a1c3c2d3bc2f6779fd0e1480d77c989adcc1bdedc661e440dbd861e7cf04682321626693281ac9c21920d45310f6b6
|
data/.rubocop.yml
CHANGED
@@ -2,12 +2,8 @@ inherit_from:
|
|
2
2
|
- https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml
|
3
3
|
- .rubocop_todo.yml
|
4
4
|
|
5
|
-
# local repo-specific modifications
|
6
|
-
# ...
|
7
|
-
#
|
8
5
|
require:
|
9
6
|
- rubocop-performance
|
10
|
-
- rubocop-rails
|
11
7
|
- rubocop-rake
|
12
8
|
- rubocop-rspec
|
13
9
|
|
@@ -15,5 +11,4 @@ AllCops:
|
|
15
11
|
TargetRubyVersion: 3.0
|
16
12
|
NewCops: enable
|
17
13
|
Exclude:
|
18
|
-
- 'lib/sts/mapper.rb'
|
19
14
|
- 'vendor/**/*'
|
data/.rubocop_todo.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2024-
|
3
|
+
# on 2024-08-15 09:04:06 UTC using RuboCop version 1.65.1.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
@@ -14,7 +14,7 @@ Gemspec/RequireMFA:
|
|
14
14
|
Exclude:
|
15
15
|
- 'lutaml-model.gemspec'
|
16
16
|
|
17
|
-
# Offense count:
|
17
|
+
# Offense count: 28
|
18
18
|
# This cop supports safe autocorrection (--autocorrect).
|
19
19
|
# Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
|
20
20
|
# URISchemes: http, https
|
@@ -22,10 +22,10 @@ Layout/LineLength:
|
|
22
22
|
Exclude:
|
23
23
|
- 'lib/lutaml/model/serialize.rb'
|
24
24
|
- 'lib/lutaml/model/type.rb'
|
25
|
-
- 'lib/lutaml/model/xml_adapter.rb'
|
26
25
|
- 'lib/lutaml/model/xml_adapter/nokogiri_adapter.rb'
|
27
26
|
- 'lib/lutaml/model/xml_adapter/ox_adapter.rb'
|
28
|
-
- '
|
27
|
+
- 'lib/lutaml/model/xml_adapter/xml_document.rb'
|
28
|
+
- 'spec/lutaml/model/delegation_spec.rb'
|
29
29
|
|
30
30
|
# Offense count: 20
|
31
31
|
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes, Max.
|
@@ -33,9 +33,9 @@ Metrics/AbcSize:
|
|
33
33
|
Exclude:
|
34
34
|
- 'lib/lutaml/model/serialize.rb'
|
35
35
|
- 'lib/lutaml/model/type.rb'
|
36
|
-
- 'lib/lutaml/model/xml_adapter.rb'
|
37
36
|
- 'lib/lutaml/model/xml_adapter/nokogiri_adapter.rb'
|
38
37
|
- 'lib/lutaml/model/xml_adapter/ox_adapter.rb'
|
38
|
+
- 'lib/lutaml/model/xml_adapter/xml_document.rb'
|
39
39
|
|
40
40
|
# Offense count: 3
|
41
41
|
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode.
|
@@ -43,50 +43,35 @@ Metrics/AbcSize:
|
|
43
43
|
Metrics/BlockLength:
|
44
44
|
Max: 30
|
45
45
|
|
46
|
-
# Offense count:
|
46
|
+
# Offense count: 19
|
47
47
|
# Configuration parameters: AllowedMethods, AllowedPatterns, Max.
|
48
48
|
Metrics/CyclomaticComplexity:
|
49
49
|
Exclude:
|
50
50
|
- 'lib/lutaml/model/serialize.rb'
|
51
51
|
- 'lib/lutaml/model/type.rb'
|
52
|
-
- 'lib/lutaml/model/xml_adapter.rb'
|
53
52
|
- 'lib/lutaml/model/xml_adapter/nokogiri_adapter.rb'
|
54
53
|
- 'lib/lutaml/model/xml_adapter/ox_adapter.rb'
|
54
|
+
- 'lib/lutaml/model/xml_adapter/xml_document.rb'
|
55
55
|
|
56
|
-
# Offense count:
|
56
|
+
# Offense count: 27
|
57
57
|
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
|
58
58
|
Metrics/MethodLength:
|
59
|
-
Max:
|
59
|
+
Max: 41
|
60
60
|
|
61
|
-
# Offense count:
|
61
|
+
# Offense count: 4
|
62
62
|
# Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
|
63
63
|
Metrics/ParameterLists:
|
64
64
|
Max: 9
|
65
65
|
|
66
|
-
# Offense count:
|
66
|
+
# Offense count: 17
|
67
67
|
# Configuration parameters: AllowedMethods, AllowedPatterns, Max.
|
68
68
|
Metrics/PerceivedComplexity:
|
69
69
|
Exclude:
|
70
70
|
- 'lib/lutaml/model/serialize.rb'
|
71
71
|
- 'lib/lutaml/model/type.rb'
|
72
|
-
- 'lib/lutaml/model/xml_adapter.rb'
|
73
72
|
- 'lib/lutaml/model/xml_adapter/nokogiri_adapter.rb'
|
74
73
|
- 'lib/lutaml/model/xml_adapter/ox_adapter.rb'
|
75
|
-
|
76
|
-
# Offense count: 2
|
77
|
-
# This cop supports unsafe autocorrection (--autocorrect-all).
|
78
|
-
RSpec/BeEq:
|
79
|
-
Exclude:
|
80
|
-
- 'spec/lutaml/model/collection_spec.rb'
|
81
|
-
- 'spec/lutaml/model/simple_model_spec.rb'
|
82
|
-
|
83
|
-
# Offense count: 1
|
84
|
-
# This cop supports safe autocorrection (--autocorrect).
|
85
|
-
# Configuration parameters: EnforcedStyle.
|
86
|
-
# SupportedStyles: be, be_nil
|
87
|
-
RSpec/BeNil:
|
88
|
-
Exclude:
|
89
|
-
- 'spec/lutaml/model_spec.rb'
|
74
|
+
- 'lib/lutaml/model/xml_adapter/xml_document.rb'
|
90
75
|
|
91
76
|
# Offense count: 6
|
92
77
|
# Configuration parameters: Prefixes, AllowedPatterns.
|
@@ -97,22 +82,10 @@ RSpec/ContextWording:
|
|
97
82
|
- 'spec/lutaml/model/xml_adapter/oga_adapter_spec.rb'
|
98
83
|
- 'spec/lutaml/model/xml_adapter/ox_adapter_spec.rb'
|
99
84
|
|
100
|
-
# Offense count:
|
101
|
-
# This cop supports unsafe autocorrection (--autocorrect-all).
|
102
|
-
# Configuration parameters: SkipBlocks, EnforcedStyle, OnlyStaticConstants.
|
103
|
-
# SupportedStyles: described_class, explicit
|
104
|
-
RSpec/DescribedClass:
|
105
|
-
Exclude:
|
106
|
-
- 'spec/address_spec.rb'
|
107
|
-
- 'spec/lutaml/model/custom_serialization_spec.rb'
|
108
|
-
- 'spec/lutaml/model/defaults_spec.rb'
|
109
|
-
- 'spec/lutaml/model/render_nil_spec.rb'
|
110
|
-
- 'spec/person_spec.rb'
|
111
|
-
|
112
|
-
# Offense count: 60
|
85
|
+
# Offense count: 63
|
113
86
|
# Configuration parameters: CountAsOne.
|
114
87
|
RSpec/ExampleLength:
|
115
|
-
Max:
|
88
|
+
Max: 35
|
116
89
|
|
117
90
|
# Offense count: 2
|
118
91
|
# Configuration parameters: Max, AllowedIdentifiers, AllowedPatterns.
|
@@ -120,27 +93,19 @@ RSpec/IndexedLet:
|
|
120
93
|
Exclude:
|
121
94
|
- 'spec/address_spec.rb'
|
122
95
|
|
123
|
-
# Offense count: 3
|
124
|
-
# This cop supports safe autocorrection (--autocorrect).
|
125
|
-
# Configuration parameters: AutoCorrect.
|
126
|
-
RSpec/LetBeforeExamples:
|
127
|
-
Exclude:
|
128
|
-
- 'spec/lutaml/model/defaults_spec.rb'
|
129
|
-
- 'spec/person_spec.rb'
|
130
|
-
|
131
96
|
# Offense count: 4
|
132
97
|
RSpec/MultipleDescribes:
|
133
98
|
Exclude:
|
134
99
|
- 'spec/lutaml/model/json_adapter_spec.rb'
|
135
100
|
- 'spec/lutaml/model/toml_adapter_spec.rb'
|
101
|
+
- 'spec/lutaml/model/xml_adapter/xml_namespace_spec.rb'
|
136
102
|
- 'spec/lutaml/model/xml_adapter_spec.rb'
|
137
|
-
- 'spec/lutaml/model/xml_namespace_spec.rb'
|
138
103
|
|
139
|
-
# Offense count:
|
104
|
+
# Offense count: 63
|
140
105
|
RSpec/MultipleExpectations:
|
141
106
|
Max: 15
|
142
107
|
|
143
|
-
# Offense count:
|
108
|
+
# Offense count: 11
|
144
109
|
# Configuration parameters: AllowSubject.
|
145
110
|
RSpec/MultipleMemoizedHelpers:
|
146
111
|
Max: 9
|
@@ -149,59 +114,13 @@ RSpec/MultipleMemoizedHelpers:
|
|
149
114
|
RSpec/PendingWithoutReason:
|
150
115
|
Exclude:
|
151
116
|
- 'spec/lutaml/model/xml_adapter/oga_adapter_spec.rb'
|
117
|
+
- 'spec/lutaml/model/xml_adapter/xml_namespace_spec.rb'
|
152
118
|
- 'spec/lutaml/model/xml_adapter_spec.rb'
|
153
|
-
- 'spec/lutaml/model/xml_namespace_spec.rb'
|
154
|
-
|
155
|
-
# Offense count: 3
|
156
|
-
# This cop supports safe autocorrection (--autocorrect).
|
157
|
-
# Configuration parameters: AutoCorrect.
|
158
|
-
RSpec/ScatteredLet:
|
159
|
-
Exclude:
|
160
|
-
- 'spec/lutaml/model/defaults_spec.rb'
|
161
|
-
- 'spec/person_spec.rb'
|
162
119
|
|
163
|
-
# Offense count:
|
120
|
+
# Offense count: 1
|
164
121
|
# Configuration parameters: Include, CustomTransform, IgnoreMethods, IgnoreMetadata.
|
165
122
|
# Include: **/*_spec.rb
|
166
123
|
RSpec/SpecFilePathFormat:
|
167
124
|
Exclude:
|
125
|
+
- '**/spec/routing/**/*'
|
168
126
|
- 'spec/lutaml/model/collection_spec.rb'
|
169
|
-
- 'spec/lutaml/model/xml_adapter/nokogiri_adapter_spec.rb'
|
170
|
-
- 'spec/lutaml/model/xml_adapter/oga_adapter_spec.rb'
|
171
|
-
- 'spec/lutaml/model/xml_adapter/ox_adapter_spec.rb'
|
172
|
-
- 'spec/lutaml/model/yaml_adapter_spec.rb'
|
173
|
-
|
174
|
-
# Offense count: 2
|
175
|
-
# This cop supports unsafe autocorrection (--autocorrect-all).
|
176
|
-
# Configuration parameters: Whitelist, AllowedMethods, AllowedReceivers.
|
177
|
-
# Whitelist: find_by_sql, find_by_token_for
|
178
|
-
# AllowedMethods: find_by_sql, find_by_token_for
|
179
|
-
# AllowedReceivers: Gem::Specification, page
|
180
|
-
Rails/DynamicFindBy:
|
181
|
-
Exclude:
|
182
|
-
- 'lib/lutaml/model/xml_adapter/nokogiri_adapter.rb'
|
183
|
-
- 'lib/lutaml/model/xml_adapter/ox_adapter.rb'
|
184
|
-
|
185
|
-
# Offense count: 1
|
186
|
-
# This cop supports unsafe autocorrection (--autocorrect-all).
|
187
|
-
Rails/NegateInclude:
|
188
|
-
Exclude:
|
189
|
-
- 'lib/lutaml/model/serialize.rb'
|
190
|
-
|
191
|
-
# Offense count: 2
|
192
|
-
# This cop supports safe autocorrection (--autocorrect).
|
193
|
-
# Configuration parameters: NotNilAndNotEmpty, NotBlank, UnlessBlank.
|
194
|
-
Rails/Present:
|
195
|
-
Exclude:
|
196
|
-
- 'lib/lutaml/model/serialize.rb'
|
197
|
-
- 'lib/lutaml/model/xml_namespace.rb'
|
198
|
-
|
199
|
-
# Offense count: 6
|
200
|
-
# This cop supports unsafe autocorrection (--autocorrect-all).
|
201
|
-
# Configuration parameters: EnforcedStyle.
|
202
|
-
# SupportedStyles: strict, flexible
|
203
|
-
Rails/TimeZone:
|
204
|
-
Exclude:
|
205
|
-
- 'lib/lutaml/model/type.rb'
|
206
|
-
- 'lib/lutaml/model/type/time_without_date.rb'
|
207
|
-
- 'spec/person_spec.rb'
|
data/Gemfile
CHANGED
@@ -5,32 +5,17 @@ source "https://rubygems.org"
|
|
5
5
|
# Specify your gem's dependencies in lutaml-model.gemspec
|
6
6
|
gemspec
|
7
7
|
|
8
|
-
gem "rake", "~> 13.0"
|
9
|
-
|
10
|
-
gem "rspec", "~> 3.0"
|
11
|
-
|
12
|
-
gem "rubocop", "~> 1.21"
|
13
|
-
|
14
8
|
gem "equivalent-xml"
|
15
|
-
|
16
9
|
gem "multi_json"
|
17
|
-
|
18
10
|
gem "nokogiri"
|
19
|
-
|
20
11
|
gem "oga"
|
21
|
-
|
22
12
|
gem "ox"
|
23
|
-
|
24
13
|
gem "pry"
|
25
|
-
|
14
|
+
gem "rake", "~> 13.0"
|
15
|
+
gem "rspec", "~> 3.0"
|
16
|
+
gem "rubocop", "~> 1.21"
|
26
17
|
gem "rubocop-performance", require: false
|
27
|
-
|
28
|
-
gem "rubocop-rails", require: false
|
29
|
-
|
30
18
|
gem "rubocop-rake", require: false
|
31
|
-
|
32
19
|
gem "rubocop-rspec", require: false
|
33
|
-
|
34
20
|
gem "tomlib"
|
35
|
-
|
36
21
|
gem "toml-rb"
|
data/README.adoc
CHANGED
@@ -116,6 +116,68 @@ end
|
|
116
116
|
|
117
117
|
== Defining attributes
|
118
118
|
|
119
|
+
=== Supported attribute value types
|
120
|
+
|
121
|
+
Lutaml::Model supports the following attribute types, they can be
|
122
|
+
referred by a string, a symbol, or their class constant.
|
123
|
+
|
124
|
+
Syntax:
|
125
|
+
|
126
|
+
[source,ruby]
|
127
|
+
----
|
128
|
+
attribute :name_of_attribute, {symbol | string | class}
|
129
|
+
----
|
130
|
+
|
131
|
+
|===
|
132
|
+
| String | Symbol | Class name | Actual value class
|
133
|
+
|
134
|
+
| `String` | `:string` | `Lutaml::Model::Type::String` | `::String`
|
135
|
+
| `Integer` | `:integer` | `Lutaml::Model::Type::Integer` | `::Integer`
|
136
|
+
| `Float` | `:float` | `Lutaml::Model::Type::Float` | `::Float`
|
137
|
+
| `Date` | `:date` | `Lutaml::Model::Type::Date` | `::Date`
|
138
|
+
| `Time` | `:time` | `Lutaml::Model::Type::Time` | `::Time`
|
139
|
+
| `DateTime` | `:date_time` | `Lutaml::Model::Type::DateTime` | `::DateTime`
|
140
|
+
| `TimeWithoutDate` | `:time_without_date` | `Lutaml::Model::Type::TimeWithoutDate` | `::Time`
|
141
|
+
| `Boolean` | `:boolean` | `Lutaml::Model::Type::Boolean` | `Boolean`
|
142
|
+
| `Decimal` | `:decimal` | `Lutaml::Model::Type::Decimal` | `::BigDecimal`
|
143
|
+
| `Hash` | `:hash` | `Lutaml::Model::Type::Hash` | `::Hash`
|
144
|
+
| `Uuid` | `:uuid` | `Lutaml::Model::Type::Uuid` | `::String`
|
145
|
+
| `Symbol` | `:symbol` | `Lutaml::Model::Type::Symbol` | `Symbol`
|
146
|
+
| `Binary` | `:binary` | `Lutaml::Model::Type::Binary` | `Binary`
|
147
|
+
| `Url` | `:url` | `Lutaml::Model::Type::Url` | `::URI`
|
148
|
+
| `IpAddress` | `:ip_address` | `Lutaml::Model::Type::IpAddress` | `::IPAddr`
|
149
|
+
| `Json` | `:json` | `Lutaml::Model::Type::Json` | `::JSON`
|
150
|
+
|
151
|
+
|===
|
152
|
+
|
153
|
+
|
154
|
+
.Defining attributes with supported types via symbol, string and class
|
155
|
+
[example]
|
156
|
+
====
|
157
|
+
[source,ruby]
|
158
|
+
----
|
159
|
+
class Studio < Lutaml::Model::Serializable
|
160
|
+
# The following are equivalent
|
161
|
+
attribute :location, :string
|
162
|
+
attribute :potter, "String"
|
163
|
+
attribute :kiln, Lutaml::Model::Type::String
|
164
|
+
end
|
165
|
+
----
|
166
|
+
|
167
|
+
[source,ruby]
|
168
|
+
----
|
169
|
+
> s = Studio.new(location: 'London', potter: 'John Doe', kiln: 'Kiln 1')
|
170
|
+
> # <Studio:0x0000000104ac7240 @location="London", @potter="John Doe", @kiln="Kiln 1">
|
171
|
+
> s.location
|
172
|
+
> # "London"
|
173
|
+
> s.potter
|
174
|
+
> # "John Doe"
|
175
|
+
> s.kiln
|
176
|
+
> # "Kiln 1"
|
177
|
+
----
|
178
|
+
====
|
179
|
+
|
180
|
+
|
119
181
|
=== Attribute as a collection
|
120
182
|
|
121
183
|
Define attributes as collections (arrays or hashes) to store multiple values
|
@@ -1200,6 +1262,28 @@ In this example:
|
|
1200
1262
|
Lutaml::Model uses an adapter pattern to support multiple libraries for each
|
1201
1263
|
serialization format.
|
1202
1264
|
|
1265
|
+
You will need to specify the configuration for the adapter you want to use. The
|
1266
|
+
easiest way is to copy and paste the following configuration into your code.
|
1267
|
+
|
1268
|
+
The default configuration is as follows:
|
1269
|
+
|
1270
|
+
[source,ruby]
|
1271
|
+
----
|
1272
|
+
require 'lutaml/model'
|
1273
|
+
require 'lutaml/model/xml_adapter/nokogiri_adapter'
|
1274
|
+
require 'lutaml/model/json_adapter/standard_json_adapter'
|
1275
|
+
require 'lutaml/model/toml_adapter/toml_rb_adapter'
|
1276
|
+
require 'lutaml/model/yaml_adapter/standard_yaml_adapter'
|
1277
|
+
|
1278
|
+
Lutaml::Model::Config.configure do |config|
|
1279
|
+
config.xml_adapter = Lutaml::Model::XmlAdapter::NokogiriAdapter
|
1280
|
+
config.yaml_adapter = Lutaml::Model::YamlAdapter::StandardYamlAdapter
|
1281
|
+
config.json_adapter = Lutaml::Model::JsonAdapter::StandardJsonAdapter
|
1282
|
+
config.toml_adapter = Lutaml::Model::TomlAdapter::TomlRbAdapter
|
1283
|
+
end
|
1284
|
+
----
|
1285
|
+
|
1286
|
+
|
1203
1287
|
=== XML
|
1204
1288
|
|
1205
1289
|
Lutaml::Model supports the following XML adapters:
|
@@ -1242,6 +1326,25 @@ end
|
|
1242
1326
|
----
|
1243
1327
|
|
1244
1328
|
|
1329
|
+
=== YAML
|
1330
|
+
|
1331
|
+
Lutaml::Model supports only one YAML adapter.
|
1332
|
+
|
1333
|
+
* YAML (default)
|
1334
|
+
|
1335
|
+
.Using the YAML adapter
|
1336
|
+
[source,ruby]
|
1337
|
+
----
|
1338
|
+
require 'lutaml/model'
|
1339
|
+
|
1340
|
+
Lutaml::Model::Config.configure do |config|
|
1341
|
+
require 'lutaml/model/yaml_adapter/standard_yaml_adapter'
|
1342
|
+
config.yaml_adapter = Lutaml::Model::YamlAdapter::StandardYamlAdapter
|
1343
|
+
end
|
1344
|
+
----
|
1345
|
+
|
1346
|
+
|
1347
|
+
|
1245
1348
|
=== JSON
|
1246
1349
|
|
1247
1350
|
Lutaml::Model supports the following JSON adapters:
|
@@ -1255,8 +1358,8 @@ Lutaml::Model supports the following JSON adapters:
|
|
1255
1358
|
require 'lutaml/model'
|
1256
1359
|
|
1257
1360
|
Lutaml::Model::Config.configure do |config|
|
1258
|
-
require 'lutaml/model/json_adapter/
|
1259
|
-
config.json_adapter = Lutaml::Model::JsonAdapter::
|
1361
|
+
require 'lutaml/model/json_adapter/standard_json_adapter'
|
1362
|
+
config.json_adapter = Lutaml::Model::JsonAdapter::StandardJsonAdapter
|
1260
1363
|
end
|
1261
1364
|
----
|
1262
1365
|
|
@@ -1266,8 +1369,8 @@ end
|
|
1266
1369
|
require 'lutaml/model'
|
1267
1370
|
|
1268
1371
|
Lutaml::Model::Config.configure do |config|
|
1269
|
-
require 'lutaml/model/json_adapter/
|
1270
|
-
config.json_adapter = Lutaml::Model::JsonAdapter::
|
1372
|
+
require 'lutaml/model/json_adapter/multi_json_adapter'
|
1373
|
+
config.json_adapter = Lutaml::Model::JsonAdapter::MultiJsonAdapter
|
1271
1374
|
end
|
1272
1375
|
----
|
1273
1376
|
|
@@ -1285,7 +1388,7 @@ require 'lutaml/model'
|
|
1285
1388
|
|
1286
1389
|
Lutaml::Model::Config.configure do |config|
|
1287
1390
|
require 'lutaml/model/toml_adapter/toml_rb_adapter'
|
1288
|
-
config.toml_adapter = Lutaml::Model::TomlAdapter::
|
1391
|
+
config.toml_adapter = Lutaml::Model::TomlAdapter::TomlRbAdapter
|
1289
1392
|
end
|
1290
1393
|
----
|
1291
1394
|
|
@@ -1295,7 +1398,7 @@ end
|
|
1295
1398
|
require 'lutaml/model'
|
1296
1399
|
|
1297
1400
|
Lutaml::Model::Config.configure do |config|
|
1298
|
-
config.toml_adapter = Lutaml::Model::TomlAdapter::
|
1401
|
+
config.toml_adapter = Lutaml::Model::TomlAdapter::TomlibAdapter
|
1299
1402
|
require 'lutaml/model/toml_adapter/tomlib_adapter'
|
1300
1403
|
end
|
1301
1404
|
----
|
@@ -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,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
|
data/lib/lutaml/model/schema.rb
CHANGED