arerd 0.2.0 → 0.2.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/CLAUDE.md +78 -0
- data/Gemfile.lock +1 -1
- data/README.md +4 -0
- data/lib/arerd/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ac4f8c25a6b90c5fd67ae251935edfaf44bdba168cf9057ba19d957996aac6b9
|
|
4
|
+
data.tar.gz: 905a00ce024e271515432af6b457e1ee661dc68f382172785ef5f3f577d44283
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 63dad4d9eee0ce49073f2e3afc4d3fc6697b9d421d209d19db2fa6fe55cdc8e528251ee0c40ca9f0cee32adbb72a44e72d55192a68c142c97d8df7baa9404957
|
|
7
|
+
data.tar.gz: a07a13531800f47018a60ee69cbfcd31f4fb38b771d3b1b55060eefdb005268e2584313eddc3e2be0418df4569c14c0f6ae34e1a308e86de53e991931b9cef72
|
data/CLAUDE.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Project Overview
|
|
6
|
+
|
|
7
|
+
Arerd is a Ruby gem that generates Entity-Relationship (ER) diagrams from ActiveRecord models in Mermaid format. It provides rake tasks (`db:erd:mermaid` and `db:erd:markdown`) that can be used in Rails applications.
|
|
8
|
+
|
|
9
|
+
## Common Commands
|
|
10
|
+
|
|
11
|
+
### Development Commands
|
|
12
|
+
- `bundle exec rake test` - Run all tests (Minitest)
|
|
13
|
+
- `bundle exec rake standard` - Run StandardRB linter
|
|
14
|
+
- `bundle exec rake standard:fix` - Auto-fix StandardRB violations
|
|
15
|
+
- `bundle exec rake` - Run both tests and linter (default task)
|
|
16
|
+
|
|
17
|
+
### Testing in a Rails Application
|
|
18
|
+
To test the gem in a Rails app during development:
|
|
19
|
+
- `bin/rails db:erd:mermaid` - Generate Mermaid diagram to stdout
|
|
20
|
+
- `bin/rails db:erd:markdown` - Generate Markdown-wrapped diagram to stdout
|
|
21
|
+
|
|
22
|
+
### Running a Single Test
|
|
23
|
+
```bash
|
|
24
|
+
bundle exec ruby -Ilib:test test/test_association.rb
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Code Architecture
|
|
28
|
+
|
|
29
|
+
### Core Components
|
|
30
|
+
|
|
31
|
+
#### 1. **Association Model** ([lib/arerd/association.rb](lib/arerd/association.rb))
|
|
32
|
+
The heart of the gem. Represents a bidirectional relationship between two ActiveRecord models. Key characteristics:
|
|
33
|
+
- Stores left/right model pairs with their association names and multiplicities
|
|
34
|
+
- `build` class method converts ActiveRecord reflection objects into Association instances
|
|
35
|
+
- Filters out unsupported association types (`:through`, polymorphic)
|
|
36
|
+
- **Important**: Only creates one Association object per bidirectional relationship by comparing model names lexicographically (line 85) to avoid duplicates in has_and_belongs_to_many
|
|
37
|
+
|
|
38
|
+
#### 2. **ERD Generator** ([lib/arerd/erd_generator.rb](lib/arerd/erd_generator.rb))
|
|
39
|
+
Orchestrates the diagram generation:
|
|
40
|
+
- `collect_models_and_associations`: Eager loads Rails app, collects all ApplicationRecord descendants, builds Association objects
|
|
41
|
+
- `generate_mermaid`/`generate_markdown`: Renders ERB templates with collected data
|
|
42
|
+
- Templates use Rails I18n (`model_name.human`, `human_attribute_name`) for internationalization
|
|
43
|
+
|
|
44
|
+
#### 3. **Templates** ([lib/arerd/templates/](lib/arerd/templates/))
|
|
45
|
+
- `erd.mmd.erb`: Generates Mermaid erDiagram syntax
|
|
46
|
+
- Introspects database for index information to mark FK/UK columns
|
|
47
|
+
- Maps association multiplicities to Mermaid relationship symbols (||, |o, }o, o{)
|
|
48
|
+
- `erd.md.erb`: Wraps Mermaid output in Markdown code fence
|
|
49
|
+
|
|
50
|
+
#### 4. **Railtie Integration** ([lib/arerd/railtie.rb](lib/arerd/railtie.rb))
|
|
51
|
+
Minimal Rails integration that loads rake tasks when Rails is present.
|
|
52
|
+
|
|
53
|
+
### Association Building Logic
|
|
54
|
+
|
|
55
|
+
The `Association.build` method handles different ActiveRecord association types:
|
|
56
|
+
- **has_many/has_one**: Creates Association from the "owning" side, requires `inverse_of`
|
|
57
|
+
- **has_and_belongs_to_many**: Creates only one Association per pair (avoids duplicates via name comparison)
|
|
58
|
+
- **belongs_to**: Only validates `inverse_of` presence, doesn't create Association (parent association handles it)
|
|
59
|
+
- **Filtered out**: `:through` associations, polymorphic associations
|
|
60
|
+
|
|
61
|
+
### Test Structure
|
|
62
|
+
|
|
63
|
+
Tests use Minitest with an in-memory SQLite database:
|
|
64
|
+
- [test/test_helper.rb](test/test_helper.rb): Sets up ActiveRecord connection and I18n
|
|
65
|
+
- [test/support/schema.rb](test/support/schema.rb): Defines test database schema
|
|
66
|
+
- [test/support/models.rb](test/support/models.rb): Defines test ActiveRecord models
|
|
67
|
+
- All test models must include `inverse_of` option per gem requirements
|
|
68
|
+
|
|
69
|
+
## Important Constraints
|
|
70
|
+
|
|
71
|
+
1. **All associations must specify `inverse_of` option** - The gem warns and skips associations without it
|
|
72
|
+
2. **has_many :through associations are ignored** - They're considered "virtual" associations
|
|
73
|
+
3. **Polymorphic associations are not supported** - The gem warns and skips them
|
|
74
|
+
4. **ApplicationRecord descendants only** - The gem specifically looks for `ApplicationRecord.descendants`
|
|
75
|
+
|
|
76
|
+
## StandardRB Linting
|
|
77
|
+
|
|
78
|
+
This project uses StandardRB for code style. Configuration is minimal (see [.standard.yml](.standard.yml)). Follow StandardRB conventions for all code changes.
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
data/lib/arerd/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: arerd
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Shuhei YOSHIDA
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-08-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|
|
@@ -55,6 +55,7 @@ files:
|
|
|
55
55
|
- ".editorconfig"
|
|
56
56
|
- ".standard.yml"
|
|
57
57
|
- ".tool-versions"
|
|
58
|
+
- CLAUDE.md
|
|
58
59
|
- Gemfile
|
|
59
60
|
- Gemfile.lock
|
|
60
61
|
- LICENSE
|
|
@@ -69,7 +70,8 @@ files:
|
|
|
69
70
|
- lib/arerd/templates/erd.mmd.erb
|
|
70
71
|
- lib/arerd/version.rb
|
|
71
72
|
homepage: https://github.com/yantene/arerd
|
|
72
|
-
licenses:
|
|
73
|
+
licenses:
|
|
74
|
+
- MIT
|
|
73
75
|
metadata:
|
|
74
76
|
allowed_push_host: https://rubygems.org
|
|
75
77
|
homepage_uri: https://github.com/yantene/arerd
|