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:

  1. Extend AgentCode::ResourceScope (recommended) — provides access to user, organization, and role inside the apply instance method:

module Scopes class PostScope < AgentCode::ResourceScope def apply(relation) if role == "viewer" relation.where(published: true) else relation end end end end

  1. 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