aasm-coder
Implement state machines with AASM for workflow management. Covers state transitions, guards, callbacks, and testing.
Best use case
aasm-coder is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Implement state machines with AASM for workflow management. Covers state transitions, guards, callbacks, and testing.
Teams using aasm-coder should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/aasm-coder/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How aasm-coder Compares
| Feature / Agent | aasm-coder | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Implement state machines with AASM for workflow management. Covers state transitions, guards, callbacks, and testing.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# AASM Coder
State machine patterns for managing workflow states in Rails.
## Setup
```ruby
# Gemfile
gem "aasm", "~> 5.5"
```
## Basic State Machine
```ruby
class Order < ApplicationRecord
include AASM
aasm column: :status do
state :pending, initial: true
state :paid
state :processing
state :shipped
state :cancelled
event :pay do
transitions from: :pending, to: :paid
after do
OrderMailer.payment_received(self).deliver_later
end
end
event :process do
transitions from: :paid, to: :processing
end
event :ship do
transitions from: :processing, to: :shipped
end
event :cancel do
transitions from: [:pending, :paid], to: :cancelled
before do
refund_payment if paid?
end
end
end
end
```
## Usage
```ruby
order = Order.create!
order.pending? # => true
order.may_pay? # => true
order.pay! # Transition + callbacks
order.paid? # => true
order.may_ship? # => false (must process first)
order.aasm.events # => [:process, :cancel]
# Scopes created automatically
Order.pending
Order.paid.where(user: current_user)
```
## Guards
```ruby
event :pay do
transitions from: :pending, to: :paid, guard: :payment_valid?
end
def payment_valid?
payment_method.present? && total > 0
end
# Usage
order.pay! # Raises AASM::InvalidTransition if guard fails
order.pay # Returns false (no exception)
```
## Callbacks
```ruby
aasm do
# State callbacks
state :paid, before_enter: :validate_payment,
after_enter: :send_receipt
# Event callbacks
event :ship do
before do
generate_tracking_number
end
after do
notify_customer
end
transitions from: :processing, to: :shipped
end
end
```
**Callback order:**
1. `before` (event)
2. `before_exit` (old state)
3. `before_enter` (new state)
4. State change persisted
5. `after_exit` (old state)
6. `after_enter` (new state)
7. `after` (event)
## Multiple Transitions
```ruby
event :approve do
transitions from: :pending, to: :approved, guard: :auto_approvable?
transitions from: :pending, to: :review, guard: :needs_review?
transitions from: :pending, to: :rejected # fallback
end
```
First matching guard wins.
## Error Handling
```ruby
# Safe (returns false on failure)
order.pay # => false if invalid
# Raises exception
begin
order.pay!
rescue AASM::InvalidTransition => e
Rails.logger.error("Invalid transition: #{e.message}")
end
# Check before transition
if order.may_pay?
order.pay!
end
```
## Testing State Machines
```ruby
RSpec.describe Order do
let(:order) { create(:order) }
it "starts in pending state" do
expect(order).to be_pending
end
describe "pay event" do
it "transitions to paid" do
expect { order.pay! }
.to change(order, :status).from("pending").to("paid")
end
it "sends payment received email" do
expect(OrderMailer).to receive_message_chain(:payment_received, :deliver_later)
order.pay!
end
end
describe "ship event" do
context "when pending" do
it "raises error" do
expect { order.ship! }.to raise_error(AASM::InvalidTransition)
end
end
context "when processing" do
before { order.update!(status: :processing) }
it "transitions to shipped" do
expect { order.ship! }
.to change(order, :status).to("shipped")
end
end
end
end
```
## Advanced Patterns
For multiple state machines, persistence options, and history tracking see:
- `references/aasm-patterns.md`
## Related Skills
- **`event-sourcing-coder`** - For recording domain events when state transitions should trigger notifications, webhooks, or audit trails.Related Skills
codereadr-automation
Automate Codereadr tasks via Rube MCP (Composio). Always search tools first for current schemas.
coder-docs
Index + offline snapshot of coder/coder documentation (progressive disclosure).
coder-hahomelabs
Coder workspace environment for hahomelabs.com deployments. Includes networking, ports, convex config, nhost config
ansible-coder
This skill guides writing Ansible playbooks for server configuration. Use when hardening servers, installing packages, or automating post-provisioning tasks that cloud-init cannot handle.
vibecoder-guide-legacy
Guides VibeCoder (non-technical users) through natural language development (legacy). Use when user mentions どうすればいい, 次は何, 使い方, 困った, help, what should I do. Do NOT load for: 技術者向け作業, 直接的な実装指示, レビュー.
semgrep-coderabbit-review
Two-stage code review combining fast pattern detection (Semgrep) with AI-powered semantic analysis (CodeRabbit)
python-coder
Modern Python 3.12+ development with uv, ruff, and production-ready practices. Routes to specialized skills for frameworks and testing.
mobile-security-coder
Expert in secure mobile coding practices specializing in input validation, WebView security, and mobile-specific security patterns.
harness-coder
Main coding agent for autonomous harness system. Continues work from previous sessions, implements one feature per session, coordinates with testing and review skills, and maintains clean handoffs via Archon. This is the workhorse of the harness system for multi-session development.
frontend-security-coder
Expert in secure frontend coding practices specializing in XSS prevention, output sanitization, and client-side security patterns.
formula-decoder-skill
Decodes mathematical and physical formulas using a 5-stage process: Confusion, Intuition, Symbol Mapping, Limit Testing, and Dimension Ascension. Combines the styles of Feynman, Sanderson, Euclid, and Victor for deep understanding.
atcoder-client
Interface with AtCoder for Japanese competitive programming contests