rails-query-object

Encapsulate complex ActiveRecord queries with constructor context and call methods.

Updated Nov 1, 2025
One-click install
npx skills add https://github.com/nschneble/rails-superstack --skill rails-query-object-nschneble
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rails-query-object
Source: https://github.com/nschneble/rails-superstack/tree/main/.agents/skills/rails-query-object
Command: npx skills add https://github.com/nschneble/rails-superstack --skill rails-query-object-nschneble

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Build clean, reusable adapters around complex ActiveRecord queries using a TDD-driven approach. This pattern helps isolate business logic, improve test coverage, and simplify query construction in Rails apps.

Core Features & Use Cases

  • Encapsulated query objects that wrap complex ActiveRecord queries
  • Multi-tenant aware data access using constructor context (account: or user:)
  • Clear return types (ActiveRecord::Relation or Hash) with a predictable call method
  • Spec-first workflow: write specs in spec/queries/ before implementing in app/queries/

Quick Start

Write a failing spec for a new query object, implement it in app/queries, and run the specs until GREEN.

Frequently Asked Questions about rails-query-object

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I encapsulate complex ActiveRecord queries in Rails?

Query objects encapsulate complex ActiveRecord queries using a spec-first workflow. Write a failing spec in spec/queries/ before implementing the query object in app/queries/ until tests pass.

What is the best way to structure multi-tenant Rails queries for dashboards and reports?

Multi-tenant Rails dashboards and reports use query objects with a constructor context like account: or user: to isolate data access. This keeps queries maintainable and testable.

How do I test complex Rails queries using TDD?

Test complex Rails queries using a spec-first workflow by writing failing specs in spec/queries/ before implementing in app/queries/. Run the specs until GREEN to isolate business logic.

What return types should a Rails query object have?

Rails query objects use a predictable return type of ActiveRecord::Relation or Hash. They require a call method and a constructor accepting account: or user: for multi-tenant contexts.

When should I use query objects instead of scopes or class methods in Rails?

Use query objects to isolate complex ActiveRecord business logic that outgrows scopes or class methods. They provide a clear constructor context, predictable call method, and improved test coverage.