Module: Rhino::HasAutoScope

Extended by:
ActiveSupport::Concern
Included in:
RhinoModel
Defined in:
lib/rhino/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::ModelNameScope` (e.g., `Scopes::PostScope` for `Post` model).

The scope class can either:

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

module Scopes
  class PostScope < Rhino::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