rails-refactorer

Refactors Rails code to improve quality while preserving functionality and test coverage.

47|11|Updated Nov 26, 2025
One-click install
npx skills add https://github.com/majesticlabs-dev/majestic-marketplace --skill rails-refactorer
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rails-refactorer
Source: https://github.com/majesticlabs-dev/majestic-marketplace/tree/main/plugins/majestic-rails/skills/rails-refactorer
Command: npx skills add https://github.com/majesticlabs-dev/majestic-marketplace --skill rails-refactorer

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill emphasizes proactive Rails code refactoring with Rails conventions, Sandi Metz rules, and test coverage preservation.

Core Features & Use Cases

  • Conventions & Idioms: Rails-friendly refactor patterns.
  • Sandi Metz Rules: Class/method length limits and clean interfaces.
  • Test Coverage: Maintain test coverage and compatibility post-refactor.

Quick Start

Identify a long method in a model, extract a service object, and add tests ensuring coverage remains intact.

Frequently Asked Questions about rails-refactorer

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

FAQPage Schema
How do I refactor Rails code while keeping tests passing?

Refactor Rails code by applying test-driven changes: extract service objects, isolate controller actions, and update tests in parallel to maintain coverage. Run your test suite after each refactor to ensure functionality remains intact and coverage doesn't drop.

What are Sandi Metz rules and why do they matter for Rails?

Sandi Metz rules enforce clean code: classes under 100 lines, methods under 5 lines, no more than 4 parameters per method, and single responsibility. They improve Rails maintainability by reducing complexity and making controllers thin and models focused.

How do I extract a service object from a Rails model?

Identify a long method in your model, move its logic into a dedicated service class, call that service from the model, and write tests for both layers. This isolates business logic, reduces model bloat, and follows Rails conventions for cleaner architecture.

Can I refactor Rails code without breaking existing functionality?

Yes. Refactor Rails code safely by preserving test coverage throughout: maintain existing test suites, add tests for extracted components, use strong parameters and guard clauses, and verify all tests pass after each change to catch regressions immediately.

What Rails refactoring patterns improve code quality most?

Key patterns include extracting service objects for business logic, isolating custom actions into dedicated controllers, adding semantic scopes, using before_action filters properly, and renaming associations for clarity. Each follows Rails idioms and reduces complexity while maintaining test coverage.

When should I refactor a Rails controller versus a model?

Refactor controllers when they handle multiple responsibilities—extract actions into dedicated controllers and move business logic into service objects. Refactor models when methods exceed 5 lines or violate single responsibility—extract into services or scopes to keep models thin and focused.