lutaml-model 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/main.yml +27 -0
  3. data/.github/workflows/rake.yml +15 -0
  4. data/.github/workflows/release.yml +23 -0
  5. data/.gitignore +11 -0
  6. data/.rspec +3 -0
  7. data/.rubocop.yml +12 -0
  8. data/CODE_OF_CONDUCT.md +84 -0
  9. data/Gemfile +12 -0
  10. data/README.adoc +380 -0
  11. data/Rakefile +12 -0
  12. data/bin/console +11 -0
  13. data/bin/setup +8 -0
  14. data/lib/lutaml/model/attribute.rb +26 -0
  15. data/lib/lutaml/model/config.rb +14 -0
  16. data/lib/lutaml/model/json_adapter/multi_json.rb +20 -0
  17. data/lib/lutaml/model/json_adapter/standard.rb +20 -0
  18. data/lib/lutaml/model/json_adapter.rb +38 -0
  19. data/lib/lutaml/model/key_value_mapping.rb +20 -0
  20. data/lib/lutaml/model/key_value_mapping_rule.rb +10 -0
  21. data/lib/lutaml/model/mapping_rule.rb +34 -0
  22. data/lib/lutaml/model/schema/json_schema.rb +63 -0
  23. data/lib/lutaml/model/schema/relaxng_schema.rb +50 -0
  24. data/lib/lutaml/model/schema/xsd_schema.rb +54 -0
  25. data/lib/lutaml/model/schema/yaml_schema.rb +47 -0
  26. data/lib/lutaml/model/schema.rb +27 -0
  27. data/lib/lutaml/model/serializable.rb +10 -0
  28. data/lib/lutaml/model/serialize.rb +179 -0
  29. data/lib/lutaml/model/toml_adapter/toml_rb_adapter.rb +20 -0
  30. data/lib/lutaml/model/toml_adapter/tomlib_adapter.rb +20 -0
  31. data/lib/lutaml/model/toml_adapter.rb +37 -0
  32. data/lib/lutaml/model/type/time_without_date.rb +17 -0
  33. data/lib/lutaml/model/type.rb +114 -0
  34. data/lib/lutaml/model/version.rb +7 -0
  35. data/lib/lutaml/model/xml_adapter/nokogiri_adapter.rb +117 -0
  36. data/lib/lutaml/model/xml_adapter/oga_adapter.rb +75 -0
  37. data/lib/lutaml/model/xml_adapter/ox_adapter.rb +75 -0
  38. data/lib/lutaml/model/xml_adapter.rb +60 -0
  39. data/lib/lutaml/model/xml_mapping.rb +65 -0
  40. data/lib/lutaml/model/xml_mapping_rule.rb +16 -0
  41. data/lib/lutaml/model/yaml_adapter.rb +24 -0
  42. data/lib/lutaml/model.rb +21 -0
  43. data/lutaml-model.gemspec +50 -0
  44. data/sig/lutaml/model.rbs +6 -0
  45. metadata +228 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 223c53c673e167e5bf85d7eec79a95011e37db1e07849a6a005d935bd5586c0f
4
+ data.tar.gz: 4adc0dc4bc3d30b15c7901b2b997c3e4ff24ff9d92896020d038e443dda99925
5
+ SHA512:
6
+ metadata.gz: 34a4d857e96d2955581a6df37c0aff10466edb1eb57293d6a818c62b998ba2244609ac9963d676ff789c0c2e08593296bd96bf7d8c6bd628ff867718e9f8e31a
7
+ data.tar.gz: a0e0c005f90ce0d029f119f1d2013da1b2ea7d61e8a8f149c46fce3c6bbfea79237d90cb9b8fc4a5eed7ef40939f2b4a35d121ab2be034b04a897103e78b7c0e
@@ -0,0 +1,27 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ pull_request:
9
+
10
+ jobs:
11
+ build:
12
+ runs-on: ubuntu-latest
13
+ name: Ruby ${{ matrix.ruby }}
14
+ strategy:
15
+ matrix:
16
+ ruby:
17
+ - '3.2.2'
18
+
19
+ steps:
20
+ - uses: actions/checkout@v4
21
+ - name: Set up Ruby
22
+ uses: ruby/setup-ruby@v1
23
+ with:
24
+ ruby-version: ${{ matrix.ruby }}
25
+ bundler-cache: true
26
+ - name: Run the default task
27
+ run: bundle exec rake
@@ -0,0 +1,15 @@
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
3
+ name: rake
4
+
5
+ on:
6
+ push:
7
+ branches: [ master, main ]
8
+ tags: [ v* ]
9
+ pull_request:
10
+
11
+ jobs:
12
+ rake:
13
+ uses: metanorma/ci/.github/workflows/generic-rake.yml@main
14
+ secrets:
15
+ pat_token: ${{ secrets.METANORMA_CI_PAT_TOKEN }}
@@ -0,0 +1,23 @@
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
3
+ name: release
4
+
5
+ on:
6
+ workflow_dispatch:
7
+ inputs:
8
+ next_version:
9
+ description: |
10
+ Next release version. Possible values: x.y.z, major, minor, patch or pre|rc|etc
11
+ required: true
12
+ default: 'skip'
13
+ repository_dispatch:
14
+ types: [ do-release ]
15
+
16
+ jobs:
17
+ release:
18
+ uses: metanorma/ci/.github/workflows/rubygems-release.yml@main
19
+ with:
20
+ next_version: ${{ github.event.inputs.next_version }}
21
+ secrets:
22
+ rubygems-api-key: ${{ secrets.METANORMA_CI_RUBYGEMS_API_KEY }}
23
+ pat_token: ${{ secrets.METANORMA_CI_PAT_TOKEN }}
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,12 @@
1
+ inherit_from:
2
+ - https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml
3
+
4
+ # local repo-specific modifications
5
+ # ...
6
+
7
+ AllCops:
8
+ TargetRubyVersion: 2.6
9
+ NewCops: enable
10
+ Exclude:
11
+ - 'lib/sts/mapper.rb'
12
+ - 'vendor/**/*'
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at ronald.tse@ribose.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in lutaml-model.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.21"
data/README.adoc ADDED
@@ -0,0 +1,380 @@
1
+ = LutaML Ruby modeller: `Lutaml::Model`
2
+
3
+ https://github.com/lutaml/lutaml-model[image:https://img.shields.io/github/stars/lutaml/lutaml-model.svg?style=social[GitHub Stars]]
4
+ https://github.com/lutaml/lutaml-model[image:https://img.shields.io/github/forks/lutaml/lutaml-model.svg?style=social[GitHub Forks]]
5
+ image:https://img.shields.io/github/license/lutaml/lutaml-model.svg[License]
6
+ image:https://img.shields.io/github/actions/workflow/status/lutaml/lutaml-model/test.yml?branch=main[Build Status]
7
+ image:https://img.shields.io/gem/v/lutaml-model.svg[RubyGems Version]
8
+
9
+ == What is Lutaml::Model
10
+
11
+ Lutaml::Model is a lightweight library for serializing and deserializing Ruby
12
+ objects to and from various formats such as JSON, XML, YAML, and TOML. It uses
13
+ an adapter pattern to support multiple libraries for each format, providing
14
+ flexibility and extensibility for your data modeling needs.
15
+
16
+ The name "LutaML" comes from the Latin word "Lutum," which means clay, and "ML"
17
+ for Markup Language. Just as clay can be molded and modeled into beautiful and
18
+ practical end products, the Lutaml::Model gem is used for data modeling,
19
+ allowing you to shape and structure your data into useful forms.
20
+
21
+
22
+
23
+ NOTE: Lutaml::Model is designed to be compatible with the Shale data modeling
24
+ API. Shale is an amazing Ruby data modeller. Lutaml::Model is meant to address
25
+ needs that are not currently addresed by Shale.
26
+
27
+ == Introduction to Data Modeling
28
+
29
+ Data modeling is the process of creating a data model for the data to be stored
30
+ in a database or used in an application. It helps in defining the structure,
31
+ relationships, and constraints of the data, making it easier to manage and use.
32
+
33
+ Lutaml::Model simplifies data modeling in Ruby by allowing you to define models
34
+ with attributes and serialize/deserialize them to/from various formats
35
+ seamlessly.
36
+
37
+ == Features
38
+
39
+ * Define models with attributes and types
40
+ * Serialize and deserialize models to/from JSON, XML, YAML, and TOML
41
+ * Support for multiple libraries (e.g., `toml-rb`, `tomlib`)
42
+ * Configurable adapters for different serialization formats
43
+ * Support for collections and default values
44
+ * Custom serialization/deserialization methods
45
+ * XML namespaces and mappings
46
+
47
+ == Installation
48
+
49
+ Add this line to your application's Gemfile:
50
+
51
+ [source,ruby]
52
+ ----
53
+ gem 'lutaml-model'
54
+ ----
55
+
56
+ And then execute:
57
+
58
+ [source,shell]
59
+ ----
60
+ bundle install
61
+ ----
62
+
63
+ Or install it yourself as:
64
+
65
+ [source,shell]
66
+ ----
67
+ gem install lutaml-model
68
+ ----
69
+
70
+ == Writing a Data Model in Ruby
71
+
72
+ To define a model, inherit from `Lutaml::Model::Serializable` and use the `attribute` class method to define attributes.
73
+
74
+ [source,ruby]
75
+ ----
76
+ require 'lutaml/model'
77
+
78
+ class Kiln < Lutaml::Model::Serializable
79
+ attribute :brand, Lutaml::Model::Type::String
80
+ attribute :capacity, Lutaml::Model::Type::Integer
81
+ attribute :temperature, Lutaml::Model::Type::Integer
82
+ end
83
+ ----
84
+
85
+ == Translating a Data Model into Different Serialization Models
86
+
87
+ Lutaml::Model allows you to translate a data model into various serialization
88
+ formats including XML, JSON, YAML, and TOML.
89
+
90
+ === XML: Element, Attribute, Namespaces
91
+
92
+ Define XML mappings using `map_element`, `map_attribute`, and `map_content`.
93
+
94
+ [source,ruby]
95
+ ----
96
+ class Example < Lutaml::Model::Serializable
97
+ attribute :name, Lutaml::Model::Type::String
98
+ attribute :value, Lutaml::Model::Type::Integer
99
+
100
+ xml do
101
+ root 'example'
102
+ map_element 'name', to: :name
103
+ map_attribute 'value', to: :value
104
+ end
105
+ end
106
+ ----
107
+
108
+ === Key Value Data Models: JSON, YAML, TOML
109
+
110
+ Define key-value data models like JSON, YAML, and TOML using the `map` method.
111
+
112
+ [source,ruby]
113
+ ----
114
+ class Example < Lutaml::Model::Serializable
115
+ attribute :name, Lutaml::Model::Type::String
116
+ attribute :value, Lutaml::Model::Type::Integer
117
+
118
+ json do
119
+ map 'name', to: :name
120
+ map 'value', to: :value
121
+ end
122
+
123
+ yaml do
124
+ map 'name', to: :name
125
+ map 'value', to: :value
126
+ end
127
+
128
+ toml do
129
+ map 'name', to: :name
130
+ map 'value', to: :value
131
+ end
132
+ end
133
+ ----
134
+
135
+ == Develop Serialization and Deserialization Mappings
136
+
137
+ Lutaml::Model supports various methods for defining serialization and deserialization mappings.
138
+
139
+ === XML (`map_element`, `map_attribute`, `map_content`)
140
+
141
+ Use `map_element` to map XML elements, `map_attribute` to map XML attributes, and `map_content` to map text content within an XML element.
142
+
143
+ [source,ruby]
144
+ ----
145
+ class Example < Lutaml::Model::Serializable
146
+ attribute :name, Lutaml::Model::Type::String
147
+ attribute :description, Lutaml::Model::Type::String
148
+
149
+ xml do
150
+ root 'example'
151
+ map_element 'name', to: :name
152
+ map_content to: :description
153
+ end
154
+ end
155
+ ----
156
+
157
+ === JSON (`map` method)
158
+
159
+ Use the `map` method to define JSON mappings.
160
+
161
+ [source,ruby]
162
+ ----
163
+ class Example < Lutaml::Model::Serializable
164
+ attribute :name, Lutaml::Model::Type::String
165
+ attribute :value, Lutaml::Model::Type::Integer
166
+
167
+ json do
168
+ map 'name', to: :name
169
+ map 'value', to: :value
170
+ end
171
+ end
172
+ ----
173
+
174
+ === YAML
175
+
176
+ Use the `map` method to define YAML mappings.
177
+
178
+ [source,ruby]
179
+ ----
180
+ class Example < Lutaml::Model::Serializable
181
+ attribute :name, Lutaml::Model::Type::String
182
+ attribute :value, Lutaml::Model::Type::Integer
183
+
184
+ yaml do
185
+ map 'name', to: :name
186
+ map 'value', to: :value
187
+ end
188
+ end
189
+ ----
190
+
191
+ === TOML
192
+
193
+ Use the `map` method to define TOML mappings.
194
+
195
+ [source,ruby]
196
+ ----
197
+ class Example < Lutaml::Model::Serializable
198
+ attribute :name, Lutaml::Model::Type::String
199
+ attribute :value, Lutaml::Model::Type::Integer
200
+
201
+ toml do
202
+ map 'name', to: :name
203
+ map 'value', to: :value
204
+ end
205
+ end
206
+ ----
207
+
208
+ == Attribute Collections Using the `collection` Option
209
+
210
+ You can define attributes as collections (arrays or hashes) to store multiple values.
211
+
212
+ [source,ruby]
213
+ ----
214
+ class Studio < Lutaml::Model::Serializable
215
+ attribute :location, Lutaml::Model::Type::String
216
+ attribute :potters, Lutaml::Model::Type::String, collection: true
217
+ end
218
+ ----
219
+
220
+ == Attribute Defaults Using the `default` Option
221
+
222
+ Specify default values for attributes using the `default` option.
223
+
224
+ [source,ruby]
225
+ ----
226
+ class Glaze < Lutaml::Model::Serializable
227
+ attribute :color, Lutaml::Model::Type::String, default: -> { 'Clear' }
228
+ attribute :temperature, Lutaml::Model::Type::Integer, default: -> { 1050 }
229
+ end
230
+ ----
231
+
232
+ == Attribute Delegation Using the `delegate` Option
233
+
234
+ Delegate attribute mappings to nested objects using the `delegate` option.
235
+
236
+ [source,ruby]
237
+ ----
238
+ class Ceramic < Lutaml::Model::Serializable
239
+ attribute :type, Lutaml::Model::Type::String
240
+ attribute :glaze, Glaze
241
+
242
+ json do
243
+ map 'type', to: :type
244
+ map 'color', to: :color, delegate: :glaze
245
+ end
246
+ end
247
+ ----
248
+
249
+ == Attribute Serialization with Custom `from` and `to` Methods
250
+
251
+ Define custom methods for specific attribute mappings using the `with:` key for each serialization mapping block.
252
+
253
+ [source,ruby]
254
+ ----
255
+ class CustomCeramic < Lutaml::Model::Serializable
256
+ attribute :name, Lutaml::Model::Type::String
257
+ attribute :size, Lutaml::Model::Type::Integer
258
+
259
+ json do
260
+ map 'name', to: :name, with: { to: :name_to_json, from: :name_from_json }
261
+ map 'size', to: :size
262
+ end
263
+
264
+ def name_to_json(model, value)
265
+ "Masterpiece: #{value}"
266
+ end
267
+
268
+ def name_from_json(model, doc)
269
+ doc['name'].sub('Masterpiece: ', '')
270
+ end
271
+ end
272
+ ----
273
+
274
+ == Using XML Namespaces
275
+
276
+ Define XML namespaces for your models to handle namespaced XML elements.
277
+
278
+ === XML Namespace on Element
279
+
280
+ [source,ruby]
281
+ ----
282
+ class Ceramic < Lutaml::Model::Serializable
283
+ attribute :type, Lutaml::Model::Type::String
284
+ attribute :glaze, Lutaml::Model::Type::String
285
+
286
+ xml do
287
+ root 'Ceramic'
288
+ namespace 'http://example.com/ceramic'
289
+ map_element 'Type', to: :type
290
+ map_element 'Glaze', to: :glaze
291
+ end
292
+ end
293
+ ----
294
+
295
+ === XML Namespace on Attribute
296
+
297
+ [source,ruby]
298
+ ----
299
+ class Ceramic < Lutaml::Model::Serializable
300
+ attribute :type, Lutaml::Model::Type::String
301
+ attribute :glaze, Lutaml::Model::Type::String
302
+
303
+ xml do
304
+ root 'Ceramic'
305
+ map_element 'Type', to: :type
306
+ map_element 'Glaze', to: :glaze
307
+ map_attribute 'xmlns', to: :namespace, namespace: 'http://example.com/ceramic'
308
+ end
309
+ end
310
+ ----
311
+
312
+ === XML Namespace with `inherit` Option
313
+
314
+ [source,ruby]
315
+ ----
316
+ class Ceramic < Lutaml::Model::Serializable
317
+ attribute :type, Lutaml::Model::Type::String
318
+ attribute :glaze, Lutaml::Model::Type::String
319
+
320
+ xml do
321
+ root 'Ceramic'
322
+ namespace 'http://example.com/ceramic', prefix: 'cera'
323
+ map_element 'Type', to: :type, namespace: :inherit
324
+ map_element 'Glaze', to: :glaze
325
+ end
326
+ end
327
+ ----
328
+
329
+ == Adapters
330
+
331
+ Lutaml::Model uses an adapter pattern to support multiple libraries for each serialization format.
332
+
333
+ === XML: Nokogiri, Oga, Ox
334
+
335
+ [source,ruby]
336
+ ----
337
+ require 'lutaml/model'
338
+ require 'lutaml/model/xml_adapter/nokogiri_adapter'
339
+ require 'lutaml/model/xml_adapter/ox_adapter'
340
+ require 'lutaml/model/xml_adapter/oga_adapter'
341
+
342
+ Lutaml::Model::Config.configure do |config|
343
+ config.xml_adapter = Lutaml::Model::XmlAdapter::NokogiriAdapter
344
+ # Or use OxAdapter or OgaAdapter
345
+ end
346
+ ----
347
+
348
+ === JSON: `JSON` and `MultiJson`
349
+
350
+ [source,ruby]
351
+ ----
352
+ require 'lutaml/model'
353
+ require 'lutaml/model/json_adapter/standard'
354
+ require 'lutaml/model/json_adapter/multi_json'
355
+
356
+ Lutaml::Model::Config.configure do |config|
357
+ config.json_adapter = Lutaml::Model::JsonAdapter::StandardDocument
358
+ # Or use MultiJsonDocument
359
+ end
360
+ ----
361
+
362
+ === TOML: `Tomlib` and `Toml-rb`
363
+
364
+ [source,ruby]
365
+ ----
366
+ require 'lutaml/model'
367
+ require 'lutaml/model/toml_adapter/toml_rb_adapter'
368
+ require 'lutaml/model/toml_adapter/tomlib_adapter'
369
+
370
+ Lutaml::Model::Config.configure do |config|
371
+ config.toml_adapter = Lutaml::Model::TomlAdapter::TomlRbDocument
372
+ # Or use TomlibDocument
373
+ end
374
+ ----
375
+
376
+ == License and Copyright
377
+
378
+ This project is licensed under the BSD 2-clause License - see the LICENSE file for details.
379
+
380
+ This project is maintained by Ribose.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "lutaml/model"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ require "irb"
11
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+ # lib/lutaml/model/attribute.rb
2
+ module Lutaml
3
+ module Model
4
+ class Attribute
5
+ attr_reader :name, :type, :options
6
+
7
+ def initialize(name, type, options = {})
8
+ @name = name
9
+ @type = type
10
+ @options = options
11
+ end
12
+
13
+ def collection?
14
+ options[:collection] || false
15
+ end
16
+
17
+ def default
18
+ options[:default].is_a?(Proc) ? options[:default].call : options[:default]
19
+ end
20
+
21
+ def render_nil?
22
+ options.fetch(:render_nil, false)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,14 @@
1
+ # lib/lutaml/model/config.rb
2
+ module Lutaml
3
+ module Model
4
+ module Config
5
+ extend self
6
+
7
+ attr_accessor :xml_adapter, :json_adapter, :yaml_adapter, :toml_adapter
8
+
9
+ def configure
10
+ yield self
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,20 @@
1
+ # lib/lutaml/model/json_adapter/multi_json.rb
2
+ require "multi_json"
3
+ require_relative "../json_adapter"
4
+
5
+ module Lutaml
6
+ module Model
7
+ module JsonAdapter
8
+ class MultiJsonDocument < Document
9
+ def self.parse(json)
10
+ data = MultiJson.load(json)
11
+ new(data)
12
+ end
13
+
14
+ def to_json(*args)
15
+ MultiJson.dump(to_h, *args)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end