From rails-agent-skills
Guides incremental extraction of Rails app code into reusable engines: scaffolds structure, moves POROs/services/controllers, creates adapters to decouple host dependencies, verifies regression coverage per slice.
npx claudepluginhub igmarin/rails-agent-skills --plugin rails-agent-skillsThis skill uses the workspace's default tool permissions.
Use this skill when the task is to move existing code out of a Rails app and into an engine.
Guides creating, scaffolding, or refactoring Rails engines, covering types (Plain, Railtie, Engine, Mountable), namespace isolation, host-app contracts, and file structure.
Writes idiomatic Ruby code using metaprogramming, Rails patterns, and performance optimizations. Supports Rails apps, gem development, RSpec/Minitest testing, and refactoring.
Reviews and refactors Rails apps to Vanilla Rails style: thin controllers, rich domain models, no unnecessary service layers. For PR reviews, codebase analysis, simplification.
Share bugs, ideas, or general feedback.
Use this skill when the task is to move existing code out of a Rails app and into an engine.
Prefer incremental extraction over big-bang rewrites. Preserve behavior first, then improve design.
DO NOT extract and change behavior in the same step. Extraction must preserve existing behavior; refactoring and improvements belong in a separate step after the move is complete and verified.
Each slice must have: one coherent responsibility, minimal new public API, passing regression tests, and a clear next step.
| Pitfall | What to do |
|---|---|
| Extracting too much at once | One bounded slice per step; large extractions hide bugs and are hard to revert |
| Direct host references in engine | Use adapters or config; direct constants couple engine to host internals |
| Behavior changes mixed with extraction | Preserve behavior first; refactor only after the move is verified |
| Circular dependencies introduced | Verify import graph before moving each slice |
| Dummy app passes but host contract is implicit | Explicitly document and test the host app contract |
First slice (move PORO, no host model yet):
# Move the file into the engine and adjust the namespace
mkdir -p my_engine/app/services/my_engine
mv app/services/pricing/calculator.rb my_engine/app/services/my_engine/pricing_calculator.rb
# Before (in host app): module Pricing; class Calculator
# After (in engine):
module MyEngine
class PricingCalculator
def initialize(line_items)
@line_items = line_items
end
def total
@line_items.sum { |item| item.price * item.quantity }
end
end
end
Verify regression coverage still passes before proceeding to the next slice:
bundle exec rspec spec/services/pricing/ spec/requests/orders/
Move engine-local models in the same slice, or keep host models and inject via an adapter in a later slice.
Adapter for host dependency (compact):
# config seam (compact)
module MyEngine
def self.current_user_for(request)
config.current_user_provider.call(request)
end
end
# usage
OrderCreator.for_request(request) # resolves via MyEngine.current_user_for(request)
See references/adapter_examples.md for the full adapter example. Compact examples and the per-slice checklist are available at rails-engine-extraction/assets/examples.md and rails-engine-extraction/assets/checklist.json.
| Skill | When to chain |
|---|---|
| rails-engine-author | Engine structure, host contract, namespace design after extraction |
| rails-engine-testing | Dummy app, regression tests, integration verification |
| refactor-safely | Behavior-preserving refactors before or after extraction slices |