concerns-patternlisted
Install: claude install-skill ghozimahdi/gm-aiagent-plugins
## Concerns Pattern
### Why Concerns (Not Service Classes)
This plugin enforces **concerns** to organize business logic, NEVER service classes.
### Organization
| Type | Location | Module Name |
|------|----------|-------------|
| Model-specific | `app/models/model_name/concern.rb` | `ModelName::ConcernName` |
| Shared across models | `app/models/concerns/concern.rb` | `ConcernName` |
| Controller | `app/controllers/concerns/concern.rb` | `ConcernName` |
### Model-Specific Concern
```ruby
# app/models/task/status_transitions.rb
module Task::StatusTransitions
extend ActiveSupport::Concern
included do
after_commit :notify_status_change, if: :saved_change_to_status?
scope :actionable, -> { where(status: [:pending, :in_progress]) }
end
def advance!
case status
when "pending" then update!(status: :in_progress)
when "in_progress" then update!(status: :completed)
end
end
def revert!
update!(status: :pending)
end
private
def notify_status_change
TaskMailer.status_changed(self).deliver_later
end
end
```
### Including in Model
```ruby
# app/models/task.rb
class Task < ApplicationRecord
include Task::StatusTransitions
include Task::Notifications
include Task::Validations
include AttributeLabels
acts_as_paranoid
belongs_to :user
has_many :ai_scheduled_events, as: :eventable
end
```
### Shared Concern
```ruby
# app/models/concerns/attribute_labels.rb
module AttributeLabels
extend ActiveSupport::Concern