extraction-timing

Guides Rails code extraction decisions between services, concerns, queries, and form objects.

659|81|Updated Dec 9, 2025
One-click install
npx skills add https://github.com/ThibautBaissac/rails_ai_agents --skill extraction-timing
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: extraction-timing
Source: https://github.com/ThibautBaissac/rails_ai_agents/tree/main/.agents/skills/extraction-timing
Command: npx skills add https://github.com/ThibautBaissac/rails_ai_agents --skill extraction-timing

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Rails developers often struggle to decide when and where to extract code, leading to bloated models, fat controllers, premature abstractions, or service objects that wrap a single update call. This Skill provides clear thresholds and decision rules for organizing Rails code.

Core Features & Use Cases

  • Extraction Thresholds: Concrete signals for when to extract, such as controller actions exceeding ~10 lines or models exceeding ~100 lines.
  • Decision Tree: A structured flow for routing code to model scopes, query objects, service objects, concerns, presenters, or ViewComponents.
  • Settled Debates: Opinionated guidance on concerns vs service objects, STI vs polymorphic associations, and callbacks vs explicit calls.
  • Use Case: When a controller action grows to 15 lines spanning two models and an external API call, use this Skill to determine it belongs in a service object with a transaction rather than a concern or inline code.

Quick Start

Ask the AI where a piece of Rails business logic should go and whether it should be extracted into a service, concern, or query object.

Frequently Asked Questions about extraction-timing

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

FAQPage Schema
When should I extract Rails code into a service object?

Extract to a service object when a controller action exceeds roughly 10 lines of business logic, when an operation spans multiple steps or models, or when it involves external API calls. One-off operations and simple CRUD should stay inline.

What is the difference between a concern and a service object in Rails?

Concerns are for simple shared model properties like SoftDeletable or Sluggable, kept under about 30 lines. Service objects handle multi-step business operations like CreateOrder or ProcessRefund. If it is a property of the model, use a concern; if it is an operation on the model, use a service.

Should I use STI or polymorphic associations in Rails?

Use STI when subclasses share more than 80% of columns in one table with a type column. Use polymorphic associations when types have unique attributes requiring separate tables. Avoid STI when over 20% of columns are NULL for some subtypes.

When are Rails callbacks acceptable versus explicit service calls?

Callbacks are acceptable only for data normalization, such as stripping whitespace or downcasing emails. Sending emails, enqueuing jobs, calling external APIs, and creating related records with business logic must be explicit calls inside services.

What are common Rails extraction anti-patterns to avoid?

Avoid services wrapping a single model update, base classes for only two implementations, concerns with multiple responsibilities, and abstractions built for hypothetical future needs. Verify against the anti-pattern checklist before extracting.