yaml_exporter 0.1.0 → 0.2.0
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/.github/workflows/gem-push.yml +20 -29
- data/.github/workflows/test.yml +27 -0
- data/AGENTS.md +34 -0
- data/CHANGELOG.md +45 -0
- data/Gemfile.lock +106 -0
- data/README.md +772 -37
- data/RELEASING.md +45 -0
- data/Rakefile +14 -0
- data/lib/yaml_exporter/builder.rb +93 -0
- data/lib/yaml_exporter/exporter.rb +139 -0
- data/lib/yaml_exporter/importer.rb +86 -0
- data/lib/yaml_exporter/nodes/attribute.rb +70 -0
- data/lib/yaml_exporter/nodes/many_base.rb +215 -0
- data/lib/yaml_exporter/nodes/many_find_by.rb +70 -0
- data/lib/yaml_exporter/nodes/many_positional.rb +14 -0
- data/lib/yaml_exporter/nodes/many_reference.rb +73 -0
- data/lib/yaml_exporter/nodes/many_through.rb +176 -0
- data/lib/yaml_exporter/nodes/one_owned.rb +96 -0
- data/lib/yaml_exporter/nodes/one_reference.rb +72 -0
- data/lib/yaml_exporter/nodes/one_reference_of.rb +128 -0
- data/lib/yaml_exporter/schema.rb +24 -0
- data/lib/yaml_exporter/structure.rb +25 -0
- data/lib/yaml_exporter/type_inference.rb +64 -0
- data/lib/yaml_exporter/version.rb +5 -0
- data/lib/yaml_exporter.rb +53 -8
- data/script/demo_quiz.rb +78 -0
- data/yaml_exporter.gemspec +8 -9
- metadata +58 -13
- data/lib/yaml_serializable/structure_builder.rb +0 -30
- data/lib/yaml_serializable/version.rb +0 -3
- data/lib/yaml_serializable/yaml_exporter.rb +0 -196
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e760f89f11f40a2f5e94e6e44348da196bd2da09267ad7585070f21c3cf998da
|
|
4
|
+
data.tar.gz: 8a2261d83c43f0a9ad8be36e3cdb425984dc42088a6cf49d839a779d820e0a80
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 40c9ba2b0c249095bf6e88bed66cd13c4a37c6e3566c1f4d3b5308e19df475cc897215962840513b8de90d1298f675d5492c1f8315993840e27dbe77a4de204f
|
|
7
|
+
data.tar.gz: 347bb621e9f981bdb61899864b70b8659f11b65691fc67c8ccf2bc8417ae1cf0c6ae6f39a091efa1c99f3314ebc1951d650d014a217a9fb2d5970db6d579ae57
|
|
@@ -1,36 +1,27 @@
|
|
|
1
|
-
name:
|
|
1
|
+
name: Push gem
|
|
2
2
|
|
|
3
|
+
# Publishes to RubyGems when you publish a GitHub Release (tag `vX.Y.Z`).
|
|
4
|
+
# Uses RubyGems Trusted Publishing (OIDC) — no API key stored as a secret.
|
|
5
|
+
# One-time setup: on rubygems.org -> the gem -> Trusted Publishers -> add a
|
|
6
|
+
# GitHub Actions publisher for this repo with workflow `gem-push.yml`.
|
|
7
|
+
# See RELEASING.md.
|
|
3
8
|
on:
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
pull_request:
|
|
7
|
-
branches: [ "main" ]
|
|
9
|
+
release:
|
|
10
|
+
types: [published]
|
|
8
11
|
|
|
9
12
|
jobs:
|
|
10
|
-
|
|
11
|
-
name: Build + Publish
|
|
13
|
+
push:
|
|
12
14
|
runs-on: ubuntu-latest
|
|
13
15
|
permissions:
|
|
14
|
-
contents:
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
contents: write # let the action attach a build-provenance attestation to the release
|
|
17
|
+
id-token: write # required for Trusted Publishing (OIDC)
|
|
17
18
|
steps:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
- name: Publish to RubyGems
|
|
28
|
-
run: |
|
|
29
|
-
mkdir -p $HOME/.gem
|
|
30
|
-
touch $HOME/.gem/credentials
|
|
31
|
-
chmod 0600 $HOME/.gem/credentials
|
|
32
|
-
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
|
33
|
-
gem build *.gemspec
|
|
34
|
-
gem push *.gem
|
|
35
|
-
env:
|
|
36
|
-
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|
|
19
|
+
- uses: actions/checkout@v4
|
|
20
|
+
- uses: ruby/setup-ruby@v1
|
|
21
|
+
with:
|
|
22
|
+
ruby-version: '3.4'
|
|
23
|
+
bundler-cache: true
|
|
24
|
+
- run: bundle exec rake test
|
|
25
|
+
# Verifies the tag matches lib/yaml_exporter/version.rb, builds, attests,
|
|
26
|
+
# and pushes via trusted publishing.
|
|
27
|
+
- uses: rubygems/release-gem@v1
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
name: Test
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main, find_by]
|
|
6
|
+
# No branch filter — run on every PR, including ones targeting `find_by`,
|
|
7
|
+
# so a change is tested before it is merged onto its base branch.
|
|
8
|
+
pull_request:
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
test:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
name: Ruby ${{ matrix.ruby }}
|
|
14
|
+
strategy:
|
|
15
|
+
fail-fast: false
|
|
16
|
+
matrix:
|
|
17
|
+
ruby: ['3.2', '3.3', '3.4', '4.0']
|
|
18
|
+
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@v4
|
|
21
|
+
# Resolve a fresh lockfile so each Ruby gets a compatible dependency set.
|
|
22
|
+
- run: rm -f Gemfile.lock
|
|
23
|
+
- uses: ruby/setup-ruby@v1
|
|
24
|
+
with:
|
|
25
|
+
ruby-version: ${{ matrix.ruby }}
|
|
26
|
+
bundler-cache: true
|
|
27
|
+
- run: bundle exec rake test
|
data/AGENTS.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
## Cursor Cloud specific instructions
|
|
4
|
+
|
|
5
|
+
### Project overview
|
|
6
|
+
|
|
7
|
+
`yaml_exporter` is a Ruby gem that provides YAML serialization/deserialization for ActiveRecord models with JSON schema generation. It is a library (not a runnable application) — there are no servers, databases, or background services to run.
|
|
8
|
+
|
|
9
|
+
### Ruby version management
|
|
10
|
+
|
|
11
|
+
Ruby is managed via **rbenv** (installed at `~/.rbenv`). The project targets the latest stable Ruby — currently **4.0.2**.
|
|
12
|
+
|
|
13
|
+
If a future Ruby version is needed and `rbenv install <version>` fails with "definition not found", update ruby-build first:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
cd ~/.rbenv/plugins/ruby-build && git pull
|
|
17
|
+
rbenv install <version>
|
|
18
|
+
rbenv global <version>
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Then re-run `bundle install` in the workspace.
|
|
22
|
+
|
|
23
|
+
### Key commands
|
|
24
|
+
|
|
25
|
+
| Task | Command |
|
|
26
|
+
| -------------------- | ----------------------------------------------------------- |
|
|
27
|
+
| Install dependencies | `bundle install` |
|
|
28
|
+
| Build the gem | `gem build yaml_exporter.gemspec` |
|
|
29
|
+
| Verify the gem loads | `ruby -e 'require_relative "lib/yaml_exporter"; puts "OK"'` |
|
|
30
|
+
|
|
31
|
+
### Notes
|
|
32
|
+
|
|
33
|
+
- The gem depends on `activerecord`, `activesupport`, and `json-schema` at runtime. For manual testing, `sqlite3` is also needed (`gem install sqlite3`).
|
|
34
|
+
- The gemspec uses `git ls-files` to determine included files — new files must be tracked by git to be included in builds.
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here.
|
|
4
|
+
This project follows [semantic versioning](https://semver.org).
|
|
5
|
+
|
|
6
|
+
## Unreleased
|
|
7
|
+
|
|
8
|
+
## v0.2.0
|
|
9
|
+
|
|
10
|
+
A ground-up rewrite of the export/import engine and its DSL. **Breaking: nothing
|
|
11
|
+
from 0.1.0 carries over** — the module, the entry points, and the mapping API are
|
|
12
|
+
all new. See the README for the full DSL.
|
|
13
|
+
|
|
14
|
+
### Changed (breaking)
|
|
15
|
+
|
|
16
|
+
- **New mixin API.** `include YamlExporter` in the model and declare the mapping
|
|
17
|
+
in a `yaml_structure do … end` block; round-trip with the instance methods
|
|
18
|
+
`#yaml_export` / `#yaml_import`. This replaces 0.1.0's
|
|
19
|
+
`YamlSerializable::YamlExporter.export(object, structure)` / `.import` class
|
|
20
|
+
methods that took an externally built structure — the `YamlSerializable`
|
|
21
|
+
module no longer exists.
|
|
22
|
+
- **Ownership-driven DSL.** The mapping is three methods — `attributes`, `one`,
|
|
23
|
+
`many` — where shape decides ownership: a **block** owns the record
|
|
24
|
+
(YamlExporter creates, updates, and destroys records to match the YAML), while
|
|
25
|
+
**`find_by:` without a block** only resolves a reference and never creates or
|
|
26
|
+
destroys the target.
|
|
27
|
+
|
|
28
|
+
### Added
|
|
29
|
+
|
|
30
|
+
- `one` associations in three forms: owned (`one :x do … end`), a plain
|
|
31
|
+
reference (`one :x, find_by:`), and `one_reference_of` to reach a relation's
|
|
32
|
+
single record.
|
|
33
|
+
- `many` associations: owned lists, `find_by:` reference lists, positional
|
|
34
|
+
lists, `positioned_by:` ordering, and `many … through:` (with or without a
|
|
35
|
+
block).
|
|
36
|
+
- Export omits `nil` attributes by default (`yaml_export(omit_nil:)`).
|
|
37
|
+
- Text columns export as YAML multiline block scalars, with surrounding
|
|
38
|
+
whitespace stripped and emojis preserved.
|
|
39
|
+
- Column-based type inference and a JSON-schema-style description of a structure
|
|
40
|
+
via `.yaml_schema`.
|
|
41
|
+
|
|
42
|
+
### Docs
|
|
43
|
+
|
|
44
|
+
- Rewritten README covering the mental model (cardinality × ownership) and every
|
|
45
|
+
DSL form.
|
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
yaml_exporter (0.2.0)
|
|
5
|
+
activerecord (>= 5.2)
|
|
6
|
+
activesupport (>= 5.2)
|
|
7
|
+
|
|
8
|
+
GEM
|
|
9
|
+
remote: https://rubygems.org/
|
|
10
|
+
specs:
|
|
11
|
+
activemodel (8.1.3)
|
|
12
|
+
activesupport (= 8.1.3)
|
|
13
|
+
activerecord (8.1.3)
|
|
14
|
+
activemodel (= 8.1.3)
|
|
15
|
+
activesupport (= 8.1.3)
|
|
16
|
+
timeout (>= 0.4.0)
|
|
17
|
+
activesupport (8.1.3)
|
|
18
|
+
base64
|
|
19
|
+
bigdecimal
|
|
20
|
+
concurrent-ruby (~> 1.0, >= 1.3.1)
|
|
21
|
+
connection_pool (>= 2.2.5)
|
|
22
|
+
drb
|
|
23
|
+
i18n (>= 1.6, < 2)
|
|
24
|
+
json
|
|
25
|
+
logger (>= 1.4.2)
|
|
26
|
+
minitest (>= 5.1)
|
|
27
|
+
securerandom (>= 0.3)
|
|
28
|
+
tzinfo (~> 2.0, >= 2.0.5)
|
|
29
|
+
uri (>= 0.13.1)
|
|
30
|
+
base64 (0.3.0)
|
|
31
|
+
bigdecimal (4.1.1)
|
|
32
|
+
concurrent-ruby (1.3.6)
|
|
33
|
+
connection_pool (3.0.2)
|
|
34
|
+
drb (2.2.3)
|
|
35
|
+
i18n (1.14.8)
|
|
36
|
+
concurrent-ruby (~> 1.0)
|
|
37
|
+
json (2.19.3)
|
|
38
|
+
logger (1.7.0)
|
|
39
|
+
minitest (5.27.0)
|
|
40
|
+
rake (13.3.1)
|
|
41
|
+
securerandom (0.4.1)
|
|
42
|
+
sqlite3 (2.9.2-aarch64-linux-gnu)
|
|
43
|
+
sqlite3 (2.9.2-aarch64-linux-musl)
|
|
44
|
+
sqlite3 (2.9.2-arm-linux-gnu)
|
|
45
|
+
sqlite3 (2.9.2-arm-linux-musl)
|
|
46
|
+
sqlite3 (2.9.2-arm64-darwin)
|
|
47
|
+
sqlite3 (2.9.2-x86-linux-gnu)
|
|
48
|
+
sqlite3 (2.9.2-x86-linux-musl)
|
|
49
|
+
sqlite3 (2.9.2-x86_64-darwin)
|
|
50
|
+
sqlite3 (2.9.2-x86_64-linux-gnu)
|
|
51
|
+
sqlite3 (2.9.2-x86_64-linux-musl)
|
|
52
|
+
timeout (0.6.1)
|
|
53
|
+
tzinfo (2.0.6)
|
|
54
|
+
concurrent-ruby (~> 1.0)
|
|
55
|
+
uri (1.1.1)
|
|
56
|
+
|
|
57
|
+
PLATFORMS
|
|
58
|
+
aarch64-linux-gnu
|
|
59
|
+
aarch64-linux-musl
|
|
60
|
+
arm-linux-gnu
|
|
61
|
+
arm-linux-musl
|
|
62
|
+
arm64-darwin
|
|
63
|
+
x86-linux-gnu
|
|
64
|
+
x86-linux-musl
|
|
65
|
+
x86_64-darwin
|
|
66
|
+
x86_64-linux-gnu
|
|
67
|
+
x86_64-linux-musl
|
|
68
|
+
|
|
69
|
+
DEPENDENCIES
|
|
70
|
+
minitest (~> 5.0)
|
|
71
|
+
rake (~> 13.0)
|
|
72
|
+
sqlite3 (>= 1.4)
|
|
73
|
+
yaml_exporter!
|
|
74
|
+
|
|
75
|
+
CHECKSUMS
|
|
76
|
+
activemodel (8.1.3) sha256=90c05cbe4cef3649b8f79f13016191ea94c4525ce4a5c0fb7ef909c4b91c8219
|
|
77
|
+
activerecord (8.1.3) sha256=8003be7b2466ba0a2a670e603eeb0a61dd66058fccecfc49901e775260ac70ab
|
|
78
|
+
activesupport (8.1.3) sha256=21a5e0dfbd4c3ddd9e1317ec6a4d782fa226e7867dc70b0743acda81a1dca20e
|
|
79
|
+
base64 (0.3.0) sha256=27337aeabad6ffae05c265c450490628ef3ebd4b67be58257393227588f5a97b
|
|
80
|
+
bigdecimal (4.1.1) sha256=1c09efab961da45203c8316b0cdaec0ff391dfadb952dd459584b63ebf8054ca
|
|
81
|
+
concurrent-ruby (1.3.6) sha256=6b56837e1e7e5292f9864f34b69c5a2cbc75c0cf5338f1ce9903d10fa762d5ab
|
|
82
|
+
connection_pool (3.0.2) sha256=33fff5ba71a12d2aa26cb72b1db8bba2a1a01823559fb01d29eb74c286e62e0a
|
|
83
|
+
drb (2.2.3) sha256=0b00d6fdb50995fe4a45dea13663493c841112e4068656854646f418fda13373
|
|
84
|
+
i18n (1.14.8) sha256=285778639134865c5e0f6269e0b818256017e8cde89993fdfcbfb64d088824a5
|
|
85
|
+
json (2.19.3) sha256=289b0bb53052a1fa8c34ab33cc750b659ba14a5c45f3fcf4b18762dc67c78646
|
|
86
|
+
logger (1.7.0) sha256=196edec7cc44b66cfb40f9755ce11b392f21f7967696af15d274dde7edff0203
|
|
87
|
+
minitest (5.27.0) sha256=2d3b17f8a36fe7801c1adcffdbc38233b938eb0b4966e97a6739055a45fa77d5
|
|
88
|
+
rake (13.3.1) sha256=8c9e89d09f66a26a01264e7e3480ec0607f0c497a861ef16063604b1b08eb19c
|
|
89
|
+
securerandom (0.4.1) sha256=cc5193d414a4341b6e225f0cb4446aceca8e50d5e1888743fac16987638ea0b1
|
|
90
|
+
sqlite3 (2.9.2-aarch64-linux-gnu) sha256=eeb86db55645b85327ba75129e3614658d974bf4da8fdc87018a0d42c59f6e42
|
|
91
|
+
sqlite3 (2.9.2-aarch64-linux-musl) sha256=4feff91fb8c2b13688da34b5627c9d1ed9cedb3ee87a7114ec82209147f07a6d
|
|
92
|
+
sqlite3 (2.9.2-arm-linux-gnu) sha256=1ee2eb06b5301aaf5ce343a6e88d99ac932d95202d7b350f0e7b6d8d588580d7
|
|
93
|
+
sqlite3 (2.9.2-arm-linux-musl) sha256=8ca0de6aceede968de0394e22e95d549834c4d8e318f69a92a52f049878a0057
|
|
94
|
+
sqlite3 (2.9.2-arm64-darwin) sha256=d15bd9609a05f9d54930babe039585efc8cadd57517c15b64ec7dfa75158a5e9
|
|
95
|
+
sqlite3 (2.9.2-x86-linux-gnu) sha256=066bc904522f8a7072236a81237c03a4a1dfe070a25107e392de03d1e4ad0e6d
|
|
96
|
+
sqlite3 (2.9.2-x86-linux-musl) sha256=6503c76278f5e8629b12b6518ff43a9a4f6d9381de73f0b086c9fa1226db5ede
|
|
97
|
+
sqlite3 (2.9.2-x86_64-darwin) sha256=ed691b5021674d72582d03c5a38e89634b961902735fb6225273892805421d13
|
|
98
|
+
sqlite3 (2.9.2-x86_64-linux-gnu) sha256=dce83ffcb7e72f9f7aeb6e5404f15d277a45332fe18ccce8a8b3ed51e8d23aee
|
|
99
|
+
sqlite3 (2.9.2-x86_64-linux-musl) sha256=e8dd906a613f13b60f6d47ae9dda376384d9de1ab3f7e3f2fdf2fd18a871a2d7
|
|
100
|
+
timeout (0.6.1) sha256=78f57368a7e7bbadec56971f78a3f5ecbcfb59b7fcbb0a3ed6ddc08a5094accb
|
|
101
|
+
tzinfo (2.0.6) sha256=8daf828cc77bcf7d63b0e3bdb6caa47e2272dcfaf4fbfe46f8c3a9df087a829b
|
|
102
|
+
uri (1.1.1) sha256=379fa58d27ffb1387eaada68c749d1426738bd0f654d812fcc07e7568f5c57c6
|
|
103
|
+
yaml_exporter (0.2.0)
|
|
104
|
+
|
|
105
|
+
BUNDLED WITH
|
|
106
|
+
4.0.6
|