This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a Rails engine gem called standard_procedure_documents that provides configurable document templates. The gem allows creating structured documents with elements like paragraphs and forms, where forms can contain various field types for user input.
# Run all specs
bundle exec rake spec
# Run specific spec file
bundle exec rspec spec/models/documents/element_spec.rb# Prepare test database (required before running specs)
bundle exec rake app:db:test:prepare
# Install migrations in host application
bin/rails standard_procedure_documents:migrations:install db:migrate db:test:prepare- Uses
bundle exec standardrb --fixfor code formatting
- Use the ternary operator instead of
if, where possible, to keep methods short - Use ruby's endless methods to reduce the number of lines in class definitions
- In specs, avoid
letstatements and define variables within the example, so it is easy to see the exact data being tested
Documents::Element (STI base class)
Documents::Paragraph- Static HTML contentDocuments::Form- Interactive forms with fieldsDocuments::Video,Documents::Image,Documents::Download,Documents::Table,Documents::PageBreak- Other content types
Documents::FieldValue (STI base class)
- Expected subclasses (currently missing):
TextValue,DateValue,NumberValue,SignatureValue,CheckboxValue,EmailValue,FileValue, etc.
Container Pattern: Models that include Documents::Container concern can hold document elements:
- Provides
elementsassociation (ordered by position) - Provides
load_elements_from(configuration)method for building documents from YAML/JSON templates
Element Structure:
- Elements belong to a container (polymorphic)
- Forms have
section_type(static/repeating) anddisplay_type(form/table) - Forms contain FormSections, which contain FieldValues
- Uses
positioninggem for ordered associations
Template System:
- Uses
dry-validationfor schema validation - Template configurations define document structure with elements and fields
- See
lib/documents/document_definition.rband example in README.md
Engine Structure:
lib/documents/- Core business logic, validation schemasapp/models/documents/- ActiveRecord modelsspec/test_app/- Test Rails application for integration testing- Database migrations in
db/migrate/
Validation Schemas:
DocumentDefinitionSchema- Validates overall template structureElementDefinitionSchema- Validates individual elements (paragraph/form)FieldDefinitionSchema- Validates field definitions within forms
- Rails 7.1.3+
dry-validationfor schema validationstandard_procedure_has_attributesfor storing attributes in a JSON fieldpositioningfor ordered associations
The spec/test_app/ directory contains a full Rails application used for testing:
- Includes
OrderFormmodel as example container - Database configured with SQLite
- Fixtures in
spec/test_app/spec/fixtures/files/
Missing Field Value Classes: The codebase references many field value subclasses (Documents::TextValue, Documents::DateValue, etc.) that are not yet implemented but are expected by tests and validation schemas.
Missing ElementBuilder: README mentions Documents::ElementBuilder.call() but this functionality appears to be in the load_elements_from method on containers instead.