ag0os/rails-dev-plugin
Overview
This skill describes Rails service object patterns for extracting and organizing business logic into focused, testable components. It covers naming, single-responsibility design, dependency injection, and common patterns like command/query, form objects, and result objects. Use it to structure app/services and to implement clear workflows and error handling in Rails apps.
How this skill works
The skill inspects use cases where controllers or models contain complex logic and recommends extracting that logic into service classes with a single public method (typically call or perform). It explains dependency injection for testability, shows when to apply patterns such as Result Object, Form Object, Query Object, and Policy Object, and outlines testing approaches including transactional behavior and failure scenarios. It also guides organizing the app/services directory for composability.
When to use it
- Move complex controller or model logic into a dedicated service object
- Implement command/query separation for mutations vs. read-only operations
- Orchestrate multi-step workflows that need transactions and rollback
- Return structured outcomes (success/failure + payload) with a Result Object
- Encapsulate multi-model form handling or complex validation in a Form Object
Best practices
- Give services verb+noun names (CreateOrder, SendEmail) and keep one public method
- Inject dependencies (mailer, API clients) via initializer for easier testing and substitution
- Keep services small and composable—delegate steps to other service or query objects
- Use Result Objects to clearly communicate success, errors, and data to callers
- Wrap multi-step changes in transactions and test both success and failure paths
Example use cases
- CreateOrder service that validates cart, charges payment, creates records, and returns a result object
- QueryObject that encapsulates complex ActiveRecord filters and scopes for reuse across controllers
- FormObject that accepts input spanning several models and persists them in a single operation
- Interactor-style orchestrator that coordinates email notifications, analytics tracking, and state changes
- Policy Object to isolate authorization checks away from controllers and models
FAQ
No. Use services for complex, reusable, or multi-step logic. Simple CRUD that fits cleanly in models or controllers can remain there.
When should I use a Result Object?
Use a Result Object when callers need a clear success/failure outcome plus associated data or errors instead of relying on exceptions.
5 skills
This skill helps you organize Rails business logic using service objects, command/query patterns, and result objects for cleaner, testable apps.
This skill helps Rails developers design GraphQL APIs with graphql-ruby by enforcing patterns for types, mutations, resolvers, and DataLoader usage.
This skill guides you to choose the right Ruby construct (class, module, Struct, or Data) by prioritizing objects and messages over default classes.
This skill helps you build modern Rails frontends using Stimulus and Turbo patterns to enhance HTML over the wire with progressive enhancement.
This skill identifies Ruby code smells and proposes targeted refactorings using Ruby Science patterns to improve maintainability.