fowler-ruby-rails-refactoring

Assess Ruby and Rails code for refactoring opportunities and produce behavior-preserving Fowler-style transformation plans.

2|Updated May 6, 2026
One-click install
npx skills add https://github.com/bpcakes/jig-skills --skill fowler-ruby-rails-refactoring-bpcakes
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: fowler-ruby-rails-refactoring
Source: https://github.com/bpcakes/jig-skills/tree/main/plugins/jig-ruby/skills/fowler-ruby-rails-refactoring
Command: npx skills add https://github.com/bpcakes/jig-skills --skill fowler-ruby-rails-refactoring-bpcakes

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve? Ruby and Rails codebases accumulate design friction—long methods, callback-heavy models, hidden N+1 queries, and duplicated business rules—that makes future changes risky and expensive. This Skill finds genuine refactoring opportunities, validates them against real change pressure, and produces a safe, sequenced plan of small behavior-preserving transformations instead of vague rewrite suggestions. ## Core Features & Use Cases - Fowler-grounded assessment: Detects code smells using Fowler's vocabulary, validates each candidate against evidence, counterevidence, and behavioral risk, then maps findings to named refactorings like Extract Function, Split Phase, and Replace Conditional with Polymorphism. - Bundled heuristic scanner: Ships a dependency-free Ruby script that scans repositories for long methods, deep nesting, flag arguments, callback chains, default_scope, bulk bypass APIs, and queries inside loops, with Markdown and JSON output. - Read-only by default with implementation mode: Produces a ranked P1/P2/P3 plan with verification steps by default, and only edits code when explicitly asked, keeping refactoring strictly separate from bug fixes, optimizations, and migrations. - Use Case: Ask the agent to review app/models and app/controllers in a Rails app; receive a ranked refactoring plan with file locations, behavioral boundaries to preserve, step-by-step transformation sequences, and a verification plan—without any code being changed. ## Quick Start Ask the agent to review your Rails app's models and controllers for refactoring opportunities using the Fowler Ruby/Rails refactoring skill and return a ranked behavior-preserving plan without editing code.

Frequently Asked Questions about fowler-ruby-rails-refactoring

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

FAQPage Schema
How do I plan a safe refactoring of a Ruby on Rails application?

Invoke the skill with a scope such as app/models or a specific class and request a behavior-preserving refactoring plan. It inspects your Ruby and Rails versions, existing tests, and call sites, then returns a ranked plan of small Fowler-style transformations with verification steps for each.

How do I scan a Rails codebase for code smells automatically?

Run the bundled scanner with ruby scripts/scan_refactoring_opportunities.rb /path/to/repo --format markdown. It uses only the Ruby standard library and reports candidates like long methods, deep nesting, flag arguments, default_scope, and queries inside loops, which must then be confirmed by reading the code.

Does the refactoring skill modify my code automatically?

No, it operates read-only by default, inspecting code and tests and reporting a sequenced plan without editing files. It switches to implementation mode only when explicitly asked, applying one named transformation at a time with focused tests after each step.

What is the difference between refactoring and optimization in Rails?

Refactoring restructures code while preserving observable behavior, such as extracting methods or moving logic. Optimization targets measured performance, like changing eager loading or using pluck, and is classified separately by this skill so the two are never mixed in one unsafe patch.

Can the scanner prove a code smell is a real problem?

No, the scanner reports heuristic candidates only and cannot prove a smell, infer dynamic Ruby callers, or judge change pressure. Each finding must be validated by inspecting call sites, tests, runtime behavior, and change history before being included in the plan.

Does the skill support older Ruby and Rails versions?

Yes, it reads .ruby-version, Gemfile.lock, and config.load_defaults before recommending anything, and never suggests features like Data.define or newer Active Record APIs that the target project does not support.