スキル一覧に戻る
ag0os

rails-service-patterns

by ag0os

Comprehensive Claude Code plugin for Rails development

2🍴 0📅 2026年1月23日
GitHubで見るManusで実行

SKILL.md


name: rails-service-patterns description: Rails service object patterns and business logic organization. Automatically invoked when working with service objects, extracting business logic, implementing command/query patterns, or organizing app/services. Triggers on "service object", "service", "business logic", "workflow", "orchestration", "command pattern", "query object", "form object", "interactor", "result object". allowed-tools: Read, Grep, Glob

Rails Service Object Patterns

Patterns for extracting and organizing business logic in Rails applications.

When This Skill Applies

  • Extracting complex logic from controllers/models into service objects
  • Implementing command/query separation patterns
  • Handling multi-step business processes
  • Designing result objects and error handling
  • Organizing the app/services directory

Core Principles

Single Responsibility

Each service should do one thing well:

  • Name services with verb + noun: CreateOrder, SendEmail, ProcessPayment
  • Keep services focused and composable
  • One public method (typically call or perform)

Dependency Injection

Make services testable and flexible:

class NotificationService
  def initialize(mailer: UserMailer, sms_client: TwilioClient.new)
    @mailer = mailer
    @sms_client = sms_client
  end
end

Service Patterns

See patterns.md for detailed implementations of:

  • Basic Service Pattern
  • Result Object Pattern
  • Form Objects
  • Query Objects
  • Policy Objects

Quick Reference

PatternWhen to Use
Basic ServiceSimple operations with transaction handling
Result ObjectWhen callers need success/failure + data/error
Form ObjectComplex forms spanning multiple models
Query ObjectComplex ActiveRecord queries
Policy ObjectAuthorization logic (Pundit-style)

Testing Services

RSpec.describe CreateOrder do
  let(:user) { create(:user) }
  let(:service) { described_class.new(user, cart_items) }

  describe '#call' do
    it 'creates an order' do
      expect { service.call }.to change { Order.count }.by(1)
    end

    context 'when payment fails' do
      before { allow(PaymentProcessor).to receive(:charge).and_raise(PaymentError) }

      it 'rolls back the transaction' do
        expect { service.call }.not_to change { Order.count }
      end
    end
  end
end
  • patterns.md - Detailed service patterns with examples

スコア

総合スコア

55/100

リポジトリの品質指標に基づく評価

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

+10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

0/5
タグ

1つ以上のタグが設定されている

0/5

レビュー

💬

レビュー機能は近日公開予定です