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:
-
Extend
Rhino::ResourceScope(recommended) — provides access touser,organization, androleinside theapplyinstance method:
module Scopes
class PostScope < Rhino::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