Skip to content

Latest commit

 

History

History
64 lines (44 loc) · 2.75 KB

File metadata and controls

64 lines (44 loc) · 2.75 KB

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

What is Rectify

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.

Commands

# 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).

Architecture

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. .call instantiates and invokes #call, broadcasting events (:ok, :invalid, etc.) handled via on(:event) blocks in controllers.
  • Presenter (presenter.rb) — Virtus-based view models with access to view helpers via #attach_controller. Used with Rectify::ControllerHelpers#present.
  • Query (query.rb) — Wraps ActiveRecord::Relation or raw SQL results. Supports composition via | (set union/merge). NullQuery serves as identity element.

Supporting modules:

  • ControllerHelpers (controller_helpers.rb) — provides present, presenter, and expose methods for controllers
  • SqlQuery (sql_query.rb) — mixin for raw SQL query objects (define model, sql, params methods)
  • BuildFormFromModel / FormAttribute / FormatAttributesHash — internal form-building machinery
  • RSpec helpers (rspec/) — stub_query, stub_command, DatabaseReporter

Test Setup

  • Specs are in spec/lib/rectify/, fixtures in spec/fixtures/
  • Uses SQLite (spec/db/development.sqlite3), configured in spec/config/database.yml
  • Each test runs in a transaction that rolls back (see spec_helper.rb)
  • Version is in lib/rectify/version.rb

Style

  • 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