Module: AgentCode::HasAutoScope
- Extended by:
- ActiveSupport::Concern
- Included in:
- AgentCodeModel
- Defined in:
- lib/agentcode/concerns/has_auto_scope.rb
Overview
Auto-detect and apply global scopes by convention. Mirrors the Laravel HasAutoScope trait.
Looks for a scope class at Scopes::{ModelName}Scope
(e.g., Scopes::PostScope for Post model).
The scope class can either:
- Extend
AgentCode::ResourceScope(recommended) — provides access touser,organization, androleinside theapplyinstance method:
module Scopes class PostScope < AgentCode::ResourceScope def apply(relation) if role == "viewer" relation.where(published: true) else relation end end end end
- Implement
self.apply(relation)as a class method (legacy/simple):
module Scopes class PostScope def self.apply(relation) relation.where(active: true) end end end