YARD plugin for documenting Sequel ORM models.
yard-is-sequel is a YARD plugin that automatically documents Sequel ORM models by extracting information about database fields, associations, and model definitions directly from your Ruby code. It generates comprehensive documentation without requiring manual annotations for basic Sequel features.
- Automatic Field Documentation: Extracts database column information from Sequel models
- Association Detection: Documents
many_to_one,one_to_many, andmany_to_manyassociations - Sequel Model Tagging: Automatically identifies and tags classes that inherit from
Sequel::Model - Migration Support: Reads database schema from Sequel migrations
- Integration with YARD: Seamlessly integrates with existing YARD documentation workflows
Add to your Gemfile:
gem 'yard-is-sequel', '~> 0.8'Or install directly:
gem install yard-is-sequelAdd to your project's .gemspec:
spec.add_development_dependency 'yard-is-sequel', '~> 0.8'Run YARD with the plugin enabled:
$ yardoc --plugin is-sequelAdd the plugin to your .yardopts file:
--plugin is-sequel
--markup markdown
--output-dir ./doc
For field detection to work, you need to set the path to your Sequel migrations:
export SEQUEL_MIGRATIONS_DIR=/path/to/your/migrationsOr set it temporarily:
SEQUEL_MIGRATIONS_DIR=/path/to/migrations yardoc --plugin is-sequelThe plugin processes tables defined via set_dataset or dataset=. It:
- Applies migrations to an in-memory SQLite database
- Extracts column names, types, and nullability constraints
- Documents each field as an attribute with proper type annotations
Example model:
class User < Sequel::Model
set_dataset :users
endGenerated documentation will include all fields from the users table.
The plugin detects and documents Sequel associations:
class User < Sequel::Model
many_to_one :organization
one_to_many :posts
many_to_many :roles
endEach association is documented as an attribute with:
- Appropriate return types
- Association type tags
- Grouping under "Sequel Associations"
Classes inheriting from Sequel::Model are automatically tagged as Sequel models.
Set the environment variable for migrations:
export SEQUEL_MIGRATIONS_DIR=./db/migrationsCurrently, the plugin supports the following implicit configurations:
- Database fields are extracted only when
SEQUEL_MIGRATIONS_DIRis set - All Sequel models in processed files are documented
- Associations are automatically detected from method calls
# app/models/user.rb
class User < Sequel::Model(:users)
# These will be documented automatically
many_to_one :organization
one_to_many :posts
many_to_many :permissions
# Custom methods are preserved
def full_name
"#{first_name} #{last_name}"
end
endThe plugin generates documentation that includes:
- Fields Section: Database columns with types
- Associations Section: All Sequel associations
- Methods Section: Custom methods (preserved from existing YARD docs)
git clone https://github.com/inat-get/yard-is-sequel.git
cd yard-is-sequel
bundle installbundle exec rake speclib/
├── yard-is-sequel.rb # Main plugin file
├── yard-is-sequel/
│ ├── info.rb # Plugin metadata
│ ├── models.rb # Model detection handler
│ ├── associations.rb # Association handler
│ └── fields.rb # Field extraction handler
spec/ # Test files
- Fork the repository
- Create a feature branch
- Add tests for your changes
- Ensure all tests pass
- Submit a pull request
- Ruby >= 3.4
- YARD >= 0.9
- Sequel >= 5.100
- SQLite3 >= 2.9 (for migration processing)
- Field detection requires Sequel migrations
- Currently supports SQLite for schema extraction (but works with any DB via Sequel)
- Complex association options might not be fully parsed
- Database views are not currently supported
- Ensure
SEQUEL_MIGRATIONS_DIRis set correctly - Verify migrations can be applied without errors
- Check that your models use
set_datasetordataset=
- Verify association method calls are at the class level
- Check for syntax errors in association definitions
- Ensure the plugin is loaded (check YARD output)
- Verify YARD version compatibility
- Check
.yardoptsfile for correct plugin name - Try running with
--debugflag for more information
This project is licensed under the GPL-3.0-or-later License - see the LICENSE file for details.
Ivan Shikhalev
https://github.com/inat-get/yard-is-sequel
- YARD team for the excellent documentation tool
- Sequel ORM maintainers
- Contributors and users of the plugin
Note: This plugin is designed to complement existing YARD documentation. It automatically adds Sequel-specific documentation but doesn't interfere with manually written documentation.