This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Rectify is a Ruby gem (v1.1.0) that provides lightweight patterns for building maintainable Rails apps: Form Objects, Commands, Presenters, and Query Objects. It's built on Virtus (attribute definitions/coercion) and Wisper (pub/sub for Commands). Requires Ruby >= 3.0, Rails >= 7.2.2.
# Install dependencies
bundle install
# Run all specs
bundle exec rspec
# Run a single spec file
bundle exec rspec spec/lib/rectify/form_spec.rb
# Run a specific example by line number
bundle exec rspec spec/lib/rectify/form_spec.rb:42
# Lint
bundle exec rubocop
# Lint with auto-fix
bundle exec rubocop -A
# Database management (for test SQLite DB used by query specs)
rake db:migrate
rake db:schema
rake generate:migration[migration_name]Note: bundle exec rspec automatically runs rake db:migrate before specs (called in spec_helper.rb).
All gem code lives in lib/rectify/. The four core components:
- Form (
form.rb) — Virtus-based form objects with ActiveModel validations, replacing Strong Parameters. Supports population from params, models, and JSON. Nested form validation and deep context passing via#with_context. - Command (
command.rb) — Wisper-based service objects..callinstantiates and invokes#call, broadcasting events (:ok,:invalid, etc.) handled viaon(:event)blocks in controllers. - Presenter (
presenter.rb) — Virtus-based view models with access to view helpers via#attach_controller. Used withRectify::ControllerHelpers#present. - Query (
query.rb) — WrapsActiveRecord::Relationor raw SQL results. Supports composition via|(set union/merge).NullQueryserves as identity element.
Supporting modules:
ControllerHelpers(controller_helpers.rb) — providespresent,presenter, andexposemethods for controllersSqlQuery(sql_query.rb) — mixin for raw SQL query objects (definemodel,sql,paramsmethods)BuildFormFromModel/FormAttribute/FormatAttributesHash— internal form-building machineryRSpec helpers(rspec/) —stub_query,stub_command,DatabaseReporter
- Specs are in
spec/lib/rectify/, fixtures inspec/fixtures/ - Uses SQLite (
spec/db/development.sqlite3), configured inspec/config/database.yml - Each test runs in a transaction that rolls back (see
spec_helper.rb) - Version is in
lib/rectify/version.rb
- RuboCop with rubocop-performance, rubocop-rspec, rubocop-rake
- 2-space indentation, no class documentation required (
Style/Documentation: false) - Hash rocket syntax (
:key => value) is used throughout the codebase, not symbol shorthand