rails-pattern-finder
# Rails Pattern Finder
What this skill does
# Rails Pattern Finder
---
name: rails-pattern-finder
description: Finds Rails code patterns and best practices using Ref (primary), Grep, and reference patterns with WebFetch fallback
version: 1.2.0
author: Rails Workflow Team
tags: [rails, patterns, best-practices, code-examples, ref]
priority: 3
---
## Purpose
Searches the current Rails codebase for existing patterns and provides best-practice code examples. Helps agents write code consistent with project conventions.
**Replaces**: Manual codebase exploration and pattern recognition
## Usage
**Auto-invoked** when agents need code examples:
```
Agent: "How is authentication implemented in this project?"
*invokes rails-pattern-finder pattern="authentication"*
```
**Manual invocation**:
```
@rails-pattern-finder pattern="service_objects"
@rails-pattern-finder pattern="api_serialization"
@rails-pattern-finder pattern="background_jobs"
```
## Supported Patterns
See `reference.md` for complete pattern list. Common patterns:
### Architectural Patterns
- `service_objects` - Service layer implementation
- `form_objects` - Form object pattern
- `query_objects` - Complex query encapsulation
- `decorators` - Decorator/presenter pattern
- `policies` - Authorization policies (Pundit)
### API Patterns
- `api_versioning` - API version management
- `api_serialization` - JSON response formatting
- `api_authentication` - Token/JWT authentication
- `api_error_handling` - Error response patterns
### Database Patterns
- `scopes` - Named scope usage
- `concerns` - Model concern organization
- `polymorphic_associations` - Polymorphic pattern
- `sti` - Single Table Inheritance
- `database_views` - Database view usage
### Testing Patterns
- `factory_usage` - FactoryBot patterns
- `request_specs` - API request testing
- `system_specs` - System/feature testing
- `shared_examples` - RSpec shared examples
## Search Process
### Step 1: Pattern Lookup
```
Input: pattern="service_objects"
Lookup: reference.md → search_paths, file_patterns, code_patterns
```
### Step 2: Codebase Search
```
Tool: Grep
Pattern: "class.*Service$"
Glob: "app/services/**/*.rb"
Output: List of matching files
```
### Step 3: Example Extraction
```
Tool: Read
Files: [top 3 matches by relevance]
Extract: Class structure, method signatures, usage patterns
```
### Step 4: Response Formatting
```ruby
## Pattern: Service Objects
### Found in Project (3 examples):
**1. UserRegistrationService** (app/services/user_registration_service.rb)
```ruby
class UserRegistrationService
def initialize(params)
@params = params
end
def call
user = User.create!(@params)
send_welcome_email(user)
user
end
private
def send_welcome_email(user)
UserMailer.welcome(user).deliver_later
end
end
```
**2. PaymentProcessingService** (app/services/payment_processing_service.rb)
[Example code...]
### Best Practice from Rails Community:
[Fetch from reference.md or WebSearch]
**Source**: Project codebase + Rails best practices
```
## Reference Lookup
**Pattern → Search Strategy mapping** in `reference.md`:
```yaml
service_objects:
title: "Service Objects"
search_paths: ["app/services/**/*.rb"]
file_patterns: ["*_service.rb"]
code_patterns:
- "class \\w+Service"
- "def call"
best_practice_url: "https://example.com/rails-service-objects"
keywords: [service, business logic, call method]
api_serialization:
title: "API Serialization"
search_paths: ["app/serializers/**/*.rb", "app/blueprints/**/*.rb"]
file_patterns: ["*_serializer.rb", "*_blueprint.rb"]
code_patterns:
- "class \\w+Serializer"
- "ActiveModel::Serializer"
- "Blueprinter::Base"
keywords: [json, serializer, blueprint, jbuilder]
```
## Output Format
### Pattern Found in Project
```markdown
## Pattern: [Pattern Name]
### Found in Project ([N] examples):
**File**: [path/to/file.rb]
**Purpose**: [What this implementation does]
```ruby
[Code example from project]
```
**Key characteristics**:
- [Feature 1]
- [Feature 2]
**Usage in project**:
[How this pattern is used - grep for usage examples]
```
### Pattern Not Found
```markdown
## Pattern: [Pattern Name] - Not found in project
**Searched**:
- app/services/**/*.rb
- app/lib/**/*.rb
**Best Practice Implementation**:
```ruby
[Example from reference.md or external source]
```
**To implement in this project**:
1. Create: app/services/[name]_service.rb
2. Follow structure above
3. Test in: spec/services/[name]_service_spec.rb
**Similar patterns in project**:
- [Alternative pattern found]
```
### Multiple Variants Found
```markdown
## Pattern: [Pattern Name] - Multiple variants found
This project uses [N] different approaches:
### Variant 1: [Approach Name] ([N] files)
[Example code...]
### Variant 2: [Approach Name] ([N] files)
[Example code...]
**Recommendation**: [Which variant to use for consistency]
```
## Implementation Details
**Tools used** (in order of preference):
1. **Read** - Load `reference.md` pattern definitions
2. **context7_fetch** (primary) - Fetch curated patterns via Context7 MCP
3. **ref_search_documentation** (secondary) - Search Rails pattern docs via Ref MCP
4. **ref_read_url** (secondary) - Fetch specific pattern guides via Ref MCP
5. **tavily_search** (tertiary) - Optimized search via Tavily MCP
6. **Grep** - Search codebase for pattern matches
7. **Read** - Extract code examples from matching files
8. **WebFetch** (fallback) - Fetch pattern docs if MCPs not available
9. **WebSearch** (optional) - Fetch external best practices
10. **Glob** - Find files matching pattern
**Optional dependencies**:
- **context7-mcp**: Fastest pattern documentation
- **ref-tools-mcp**: Token-efficient pattern search
- **tavily-mcp**: Optimized search for LLMs
- If neither installed: Falls back to WebFetch and local searches (still works!)
**Search strategies**:
**File-based search**:
```bash
# Find files matching naming convention
glob: "app/services/*_service.rb"
```
**Content-based search**:
```bash
# Find class definitions
grep: "class \\w+Service$"
path: "app/services"
```
**Usage search**:
```bash
# Find where pattern is used
grep: "UserRegistrationService\\.new"
path: "app/controllers"
```
**Relevance ranking**:
1. Most recently modified files (likely current patterns)
2. Files with most references (commonly used)
3. Files with comprehensive examples (best for learning)
## Error Handling
**Pattern not found**:
```markdown
⚠️ Pattern "[pattern]" not found in project
**Searched**:
- [paths searched]
**Options**:
1. View best practice example (from reference.md)
2. Search for similar pattern: [suggestions]
3. Implement from scratch using best practices
```
**Invalid pattern name**:
```markdown
❌ Unknown pattern: "[pattern]"
Available patterns:
- service_objects
- form_objects
- query_objects
[...from reference.md...]
Try: @rails-pattern-finder pattern="[one of above]"
```
**Ambiguous results**:
```markdown
⚠️ Multiple pattern variants found for "[pattern]"
Please review all variants and choose one for consistency.
[List all variants found...]
```
## Integration
**Auto-invoked by**:
- All 7 Rails agents when generating new code
- @rails-architect for architectural decisions
- Agents adapting to project conventions
**Workflow**:
1. Agent needs to generate code (e.g., new service)
2. Invokes @rails-pattern-finder pattern="service_objects"
3. Receives project-specific examples
4. Generates code matching project style
## Special Features
### Pattern comparison
```
@rails-pattern-finder pattern="service_objects" compare_with="form_objects"
→ Shows differences and use cases for each
```
### Project convention detection
```
@rails-pattern-finder detect_conventions
→ Analyzes codebase and reports common patterns
```
### Anti-pattern detection
```
@rails-pattern-finder anti_patterns
→ Searches for common Rails anti-patterns in codebase
```
### Test pattern search
```
@rails-pattern-finder pattern="service_objects" include_tests=true
→ Shows both iRelated in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.