pn-ruby-backend

pn-ruby-backend is a cursor rule for Cursor from perniemann/pnCore. It costs 0 tokens per session (825 once invoked), scanned A, original, MIT.

A set of rules for writing Ruby server and API code, including applications built with Rails or Sinatra.

In plain words
What is it for?
Use it when building or reviewing Rails models, controllers, routes, service objects, database queries, and configuration.
Why use it?
It provides consistent Ruby structure and helps prevent issues such as tangled controllers, inefficient database queries, and hidden side effects.

Cursor rule for Cursor

Written for Cursor: a Cursor rule (.mdc).

Good fit Use it when building or reviewing Rails models, controllers, routes, service objects, database queries, and configuration.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/perniemann/pncore/pn-ruby-backend
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/perniemann/pnCore

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for pn-ruby-backend

README.md
[![agentmods](https://agentmods.dev/badge/rules/perniemann/pncore/pn-ruby-backend/github.svg)](https://agentmods.dev/rules/perniemann/pncore/pn-ruby-backend)
Your own site
<a href="https://agentmods.dev/rules/perniemann/pncore/pn-ruby-backend"><img src="https://agentmods.dev/badge/rules/perniemann/pncore/pn-ruby-backend/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for pn-ruby-backend

Your own site · 80×15
<a href="https://agentmods.dev/rules/perniemann/pncore/pn-ruby-backend"><img src="https://agentmods.dev/badge/rules/perniemann/pncore/pn-ruby-backend.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 825 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00000 $0.00825
Opus 5.5 $0.00000 $0.00330
Sonnet 5.5 $0.00000 $0.00165
Haiku 4.5 $0.00000 $0.00082

Measured 1mo ago against content hash a215e7686c4a, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

pn-ruby-backend scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 1mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

packages/pn-core-mcp/content/rules/pn-ruby-backend.mdc · 50 lines

How it starts

The opening of the file, as written. The whole thing — 50 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Ruby / backend rules

Style

  • Follow Ruby style: snake_case for methods/variables, PascalCase for classes/modules, SCREAMING_SNAKE for constants.
  • Indent with 2 spaces. Use frozen_string_literal: true at the top of all files.
  • Prefer explicit returns only at early-exit guard clauses. Avoid implicit returns in multi-branch methods.
  • Avoid deeply nested blocks; extract to named methods when nesting exceeds 2 levels.

Rails conventions

  • Use Rails conventions before custom abstractions: RESTful resource routes, before_action, scopes, callbacks.
  • Controller actions stay thin: validate input, call a service or model method, render result. Business logic belongs in models or service objects, not controllers.
  • Service objects for complex operations: plain Ruby objects in app/services/ with a single public #call method.
  • Avoid callbacks (before_save, after_create) for side effects that belong in service objects — they make unit testing and debugging opaque.

ActiveRecord and N+1

  • Use includes or preload for associations accessed in a loop: User.includes(:orders).
  • Use select to limit columns fetched: User.select(:id, :email) — never load full rows when only a subset is needed.
  • Use find_each (not all.each) for batch processing: User.find_each(batch_size: 500) { |u| ... }.
  • Use the Bullet gem in development to detect and alert on N+1 queries and unused eager loads.

Secrets and config

  • All secrets and config from environment variables: ENV["VAR"] or Rails credentials (Rails.application.credentials).
  • Use dotenv-rails in development; never commit .env to git. Keep .env.example with placeholder values.
  • Never hardcode API keys, tokens, or DB passwords in source, initializers, or YAML config files.

Error handling

  • Use begin/rescue with specific exception classes. Never rescue Exception — it catches SignalException (SIGTERM) and SystemExit.
  • Raise custom error classes: class PaymentFailed < StandardError; end — allows callers to catch specifically.
  • In Rails controllers: use rescue_from for centralized error formatting. Return consistent JSON shapes.
  • Use structured logging (Rails logger with semantic_logger or lograge). Include request ID, user ID in log context.

Read the full file on GitHub · 50 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 1mo ago First seen · 50 lines · 0 tokens per session scan A a215e7686c4a

Subscribe to this mod's changes

pn-ruby-backend is a cursor rule published in the GitHub repository perniemann/pnCore (0 stars, last pushed 5d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 825 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.