Module: RactorRailsShim::ARModelWalker

Extended by:
RoleDefaults
Defined in:
lib/ractor_rails_shim/roles/ar_model_walker.rb

Class Method Summary collapse

Methods included from RoleDefaults

default_funnel, default_reassign_shareable_const, default_safe_const_get

Class Method Details

.configure(funnel:) ⇒ Object

Inject the funnel collaborator — a callable responding to call(label) { block } that runs the block and rescues StandardError (matching _swallow). Passing nil (or calling reset_configuration) restores the facade-lookup default.



40
41
42
# File 'lib/ractor_rails_shim/roles/ar_model_walker.rb', line 40

def self.configure(funnel:)
  @funnel = funnel
end

.each_model(skip_abstract: false) ⇒ Object

Iterate every loaded ActiveRecord model — Base itself plus its descendants — yielding each to the block exactly once. Per-class failures are funneled through funnel so the walk continues past one bad model.

Options:

skip_abstract: true  — skip classes whose `abstract_class?` is true
                     (used by CacheWarmer, which only warms
                     concrete models). Default false so
                     ClassIvarFreezer and the attribute-method
                     warmers still visit abstract classes
                     (workers recurse into them).

Returns the count of yielded models (0 when AR is absent).



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/ractor_rails_shim/roles/ar_model_walker.rb', line 69

def self.each_model(skip_abstract: false)
  return 0 unless defined?(::ActiveRecord::Base)

  base = ::ActiveRecord::Base
  descendants =
    begin
      base.descendants
    rescue StandardError
      []
    end

  count = 0
  ([base] + descendants).each do |klass|
    next if skip_abstract && klass.respond_to?(:abstract_class?) && klass.abstract_class?
    begin
      yield klass
    rescue StandardError => e
      funnel.call("ARModelWalker #{klass}") { raise e }
    end
    count += 1
  end
  count
end

.funnelObject

The active funnel: the injected one if configured, else the facade lookup (RactorRailsShim::Funnel.method(:swallow)).



51
52
53
# File 'lib/ractor_rails_shim/roles/ar_model_walker.rb', line 51

def self.funnel
  @funnel || default_funnel
end

.reset_configurationObject

Restore the default (facade-lookup) funnel. Test seam.



45
46
47
# File 'lib/ractor_rails_shim/roles/ar_model_walker.rb', line 45

def self.reset_configuration
  @funnel = nil
end