Class: SuperAuth::ActiveRecord::Resource

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Nested
Defined in:
lib/super_auth/active_record/resource.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Nested

included

Class Method Details

.dead_type_level_nodesObject

Type-level nodes that admit nobody: their external_type names no loaded ActiveRecord class that carries the ByCurrentUser scope — the class does not exist, or the scope sits only on a nested subclass (User with the scope on User::Directory and User::Writable) — so every row compiled from them matches no model's query and nothing notices. Hosts accumulate them by moving a model to the readonly-base-plus-Writable-subclass pattern and never pruning the type list that mints the nodes; the first consumer found seven. Rails-side by necessity: only a process with the models loaded can say what a type string resolves to, which is why this is not a bucket of SuperAuth::RLS.coverage.



34
35
36
37
38
39
# File 'lib/super_auth/active_record/resource.rb', line 34

def self.dead_type_level_nodes
  where(external_id: nil).where.not(external_type: nil).reject do |node|
    klass = node.external_type.safe_constantize
    klass.is_a?(Class) && klass < ::ActiveRecord::Base && klass.include?(SuperAuth::ActiveRecord::ByCurrentUser)
  end
end

Instance Method Details

#refresh_label!Object

Re-derive the label after the application record is renamed. Hosts call it from whatever already syncs the node; super_auth:labels:backfill calls it for every row.



44
45
46
47
# File 'lib/super_auth/active_record/resource.rb', line 44

def refresh_label!
  derived = derived_label
  update_column(:super_auth_label, derived) unless derived.nil?
end