AGENT SKILL

ruby-expert

Ruby on Rails web development: ActiveRecord/PostgreSQL, BDD/TDD testing with RSpec and Capybara, service objects, background jobs with Sidekiq, and dependency management with Bundler. Use when building Rails applications, writing migrations, implementing service objects, testing Rails features, or extending Rails engines. Trigger: Ruby, Rails, RSpec, Capybara, ActiveRecord, Sidekiq. Do NOT trigger for: Go services, Python backends, frontend TypeScript.

License 许可
MIT
最近更新
2026-08-27
Stars
★ 1
Forks
0

01 前言 Front Matter

name
ruby-expert
license
MIT
metadata
{ "author": "Community", "status": "stable", "version": "1.0", "category": "backend" }
description
Ruby on Rails web development: ActiveRecord/PostgreSQL, BDD/TDD testing with RSpec and Capybara, service objects, background jobs with Sidekiq, and dependency management with Bundler. Use when building Rails applications, writing migrations, implementing service objects, testing Rails features, or extending Rails engines. Trigger: Ruby, Rails, RSpec, Capybara, ActiveRecord, Sidekiq. Do NOT trigger for: Go services, Python backends, frontend TypeScript.

02 资源文件 2

03 SKILL.md 正文

Ruby Expert

Ruby ecosystem: Rails, ActiveRecord, testing with RSpec.

Core Stack

  • Language: Ruby 3.x
  • Framework: Ruby on Rails 7+ (MVC, ActiveRecord, ActionMailer, ActiveJob)
  • Background Jobs: Sidekiq / ActiveJob
  • Database: PostgreSQL (via ActiveRecord)
  • Testing: RSpec + Capybara + FactoryBot
  • Dependencies: Bundler + Gemfile
  • Linting: RuboCop
  • Background: Sidekiq / ActiveJob

Project Structure

app/
  controllers/     # thin controllers
  models/          # ActiveRecord models + Rails decorators
  views/           # ERB/Slim templates
  services/        # business logic (service objects)
  decorators/      # model/controller decorators
db/
  migrate/         # Rails migrations
spec/
  models/
  controllers/
  features/        # Capybara integration tests
  factories/       # FactoryBot definitions
# app/models/concerns/tenant_scoped.rb
module TenantScoped
  extend ActiveSupport::Concern

  included do
    belongs_to :tenant
    default_scope { where(tenant: Current.tenant) }
  end
end

Workflow

  1. Define data model (ActiveRecord migration + model validations)
  2. Implement service objects for business logic (not in controller/model)
  3. Thin controllers: extract params -> call service -> render
  4. Write RSpec tests (unit + integration + Capybara features)
  5. RuboCop lint before commit

Testing

# spec/models/article_spec.rb
RSpec.describe Article, type: :model do
  subject { build(:article, price: 19.99) }

  it { is_expected.to validate_presence_of(:name) }
  it { is_expected.to validate_numericality_of(:price).is_greater_than(0) }

  describe "#tenant" do
    let(:tenant) { create(:tenant) }

    it "returns associated tenant name" do
      subject.tenant = tenant
      expect(subject.tenant_name).to eq(tenant.name)
    end
  end
end

# spec/features/booking_spec.rb
RSpec.feature "Booking", type: :feature do
  scenario "creates booking" do
    article = create(:article, name: "Test Item")
    visit article_path(article)
    click_button "Add to Booking"
    click_button "Submit Booking"
    expect(page).to have_content("Item confirmed")
  end
end
  • FactoryBot over fixtures. Capybara for feature specs.
  • Test decorators and concerns in isolation.

Constraints

  • NEVER modify engine source code directly — use decorators
  • NEVER skip validations in ActiveRecord (save(validate: false) only with explicit reason)
  • NEVER business logic in controllers — service objects
  • NEVER eval or class_eval on user input
  • ALWAYS use strong parameters (params.require(:model).permit(...))
  • ALWAYS run bundle exec rubocop before commit
  • NEVER log PII (customer names, emails, addresses) in plain text
  • NEVER store sensitive data in plain text — use a dedicated secrets/PII vault service

Security

  • ALWAYS run brakeman in CI (static security analysis) — fail on HIGH findings
  • ALWAYS use strong parameters; never permit mass-assignment of role/permission attributes
  • ALWAYS enable CSRF protection (protect_from_forgery) on state-changing endpoints
  • ALWAYS parameterize SQL via ActiveRecord bindings — never interpolate user input

Overview

Ruby on Rails for web application development. This skill covers ActiveRecord models and migrations, service objects, RSpec testing with Capybara, engine customization via decorators, and background job processing with Sidekiq.

Quick Reference

Component Technology Purpose
Framework Ruby on Rails 7+ MVC Web application structure
Background Jobs Sidekiq + ActiveJob Async processing, scheduled tasks, webhooks
Customization Decorators + Deface overrides Extend Rails without modifying source
Testing RSpec + Capybara + FactoryBot BDD acceptance tests
Background Sidekiq / ActiveJob Async job processing

Workflow

  1. Define data model via ActiveRecord migration + model validations
  2. Implement service objects for business logic (never in controller/model)
  3. Write thin controller: extract params → call service → render response
  4. Customize Rails via decorators (class_eval on models) and Deface overrides (views)
  5. Write RSpec tests: model specs, controller specs, Capybara feature specs
  6. Run bundle exec rubocop before commit — stop on lint failures

Anti-patterns

FAIL: Modifying Rails engine gem source code directly PASS: Always use decorators and Deface overrides

# FAIL:
# Editing rails_core gem directly — lost on bundle update
# app/models/rails/product.rb (within gem)

# PASS:
# app/decorators/rails/product_decorator.rb
Rails::Article.class_eval do
  belongs_to :tenant, class_name: "Tenant"
end

FAIL: Business logic in Rails controllers or models PASS: Extract into service objects

# FAIL:
class BookingsController < ApplicationController
  def create
    @booking = Rails::Booking.new(booking_params)
    @booking.calculate_fees   # business logic in controller
    @booking.apply_discounts   # business logic in controller
    @booking.save!
  end
end

# PASS:
class BookingService
  def call(booking_params)
    booking = Rails::Booking.new(booking_params)
    FeeCalculator.apply(booking)
    DiscountApplier.apply(booking)
    booking.save!
    booking
  end
end

FAIL: Using save(validate: false) without documented reason PASS: Always validate and handle errors explicitly

# FAIL:
booking.save(validate: false)  # why? undocumented

# PASS:
booking.save!  # raises on validation failure
# or with explicit skip documented:
booking.save(validate: false)  # Skipping validation because partial restore from archive table

References

Verification Checklist

  • [ ] Rails customizations use decorators/overrides (never modify engine source directly)
  • [ ] Business logic extracted into service objects (not in controllers or models)
  • [ ] Strong parameters used in all controllers (params.require(...).permit(...))
  • [ ] bundle exec rubocop run and all violations resolved
  • [ ] No PII logged in plain text (names, emails, addresses)
  • [ ] No sensitive data stored in plain text — routed via dedicated secrets/PII vault service
  • [ ] save(validate: false) only used with explicit documented reason
  • [ ] brakeman clean; strong parameters, CSRF protection, no mass-assignment exposure

Troubleshooting

Symptom Likely cause Fix
Rails decorator not loading File not in app/decorators/ or gem autoload order Verify file path follows Rails decorator naming convention; restart server
Migration fails on production ALTER TABLE locks or constraint violation Wrap in transaction; use safe_ methods for large tables; add NOT VALID for FK
Capybara test can't find element Selector mismatch or JS not executed Use more specific selectors; add wait: option; check for JS errors in browser console
Rails decorator loads but overridden method not called (edge case: monkey-patch load order) Another decorator or gem overrides same method; last-loaded wins Use prepend instead of class_eval for controlled override order; verify load order in config/initializers

| [WARN] Rails gem autoload order: decorator defined before original class loads | Zeitwerk (Rails 6+) autoloads in alphabetical order; decorator can load before parent class | Use Rails.configuration.to_prepare block to defer decorator loading; check class exists before reopening |

04 同仓库更多 Skills

ronsilver
ronsilver/agent-covenant

web-browsing-agent-expert

Web browsing for AI agents: driving a headless browser (Playwright, Puppeteer) from agent tooling, navigation and page-state grounding, DOM extraction and structured data capture, form interaction, session and cookie management, anti-bot mitigation awareness, and safe browsing rules (no PII exfiltration, respect robots and terms). Use when building a browsing tool or MCP server for an agent, teaching an agent to navigate and read web pages, extracting structured content from dynamic sites, or handling login walls and pagination in agent workflows. Trigger: web browsing agent, headless browser, Playwright MCP, Puppeteer, browser automation for agents, DOM extraction, page navigation, session management. Do NOT trigger for: end-to-end UI testing of an application (use playwright-expert); writing standalone scraping scripts for data pipelines (use python-expert); fetching a single public URL (use the fetch tool).

★ 1
ronsilver
ronsilver/agent-covenant

vector-databases

Design and operate vector databases for cloud-native AI features. Use when selecting between pgvector, Pinecone, or Weaviate for AI context layer or integration-hub; designing embedding schemas and index parameters; implementing ANN search with metadata filtering; managing embedding model versions; optimizing query latency; or debugging low retrieval quality. Pairs with rag-architecture for pipeline design and postgres-database-expert for pgvector specifics. Trigger: vector database, pgvector, Pinecone, Weaviate, embedding, ANN search, HNSW, cosine similarity. Do NOT trigger for: relational SQL optimization, standard PostgreSQL schema design, Redis caching.

★ 1
ronsilver
ronsilver/agent-covenant

typescript-expert

Full-stack TypeScript stack for modern projects: frontend SSR/CSR with Next.js 14 App Router and React, backend APIs with Node.js (Express/Fastify), state management with Zustand/Redux Toolkit, unit and integration testing with Vitest/Jest + React Testing Library + MSW, and static analysis with ESLint/Prettier/tsc. Use when building React components or hooks, implementing Next.js App Router or Server Components, writing Node.js REST API handlers, implementing middleware (auth, rate-limit, logging), managing client state (Zustand/RTK), writing frontend/backend tests, or running TypeScript linting/type checks. Trigger: TypeScript, Next.js, React, Zustand, Node.js, Express, Fastify, MSW, Vitest. Do NOT trigger for: Python backend development, Go microservices, iOS/mobile development.

★ 1
ronsilver
ronsilver/agent-covenant

tool-usage

Guide correct tool selection, design, and orchestration for AI agents. Use when choosing between dedicated vs Bash tools, designing MCP tool interfaces, naming tool parameters, handling tool response limits, orchestrating parallel vs sequential calls, evaluating tool accuracy, applying ACI design principles, selecting workflow patterns, or reading/filtering/transforming/generating structured data (JSON, YAML, CSV, TOML, XML). Trigger: tool selection, MCP tool design, orchestration, ACI, parallel execution, composite tool, structured data, jq, yq, dasel, mlr, csvkit. Do NOT trigger for: writing application business logic, domain-specific development (route to domain skill), database migrations.

★ 1
ronsilver
ronsilver/agent-covenant

token-efficiency

Enforce token-efficient output, compression, caching, and model routing. Use when calibrating response verbosity, applying compression strategies to logs or RAG chunks, routing tasks to the right model tier, setting thinking budgets, enforcing word limits, compressing context before reinitiation, applying KV-cache ordering, masking tool output observations, or applying clarification-first protocol before irreversible actions. Trigger: token efficiency, compression, model routing, thinking budget, KV-cache, clarification protocol. Do NOT trigger for: non-agent tooling, CI/CD pipeline scripting, infrastructure provisioning.

★ 1
ronsilver
ronsilver/agent-covenant

time-series-db

Time-series database patterns for cloud-native metrics and analytics: TimescaleDB, InfluxDB, and Amazon Timestream selection; continuous aggregates, retention policies, downsampling, and integration with Prometheus/Grafana. Use when storing business metrics over time, building custom business dashboards, designing high-frequency event storage, or querying time-bucketed aggregations. Trigger: time-series, TimescaleDB, InfluxDB, Prometheus, Grafana, hypertable, continuous aggregate, retention policy. Do NOT trigger for: relational PostgreSQL schema design, NoSQL document stores, Kafka event streaming.

★ 1