Class: RactorRailsShim::Callbacks::DependentAssociationTransport
- Inherits:
-
Object
- Object
- RactorRailsShim::Callbacks::DependentAssociationTransport
- Defined in:
- lib/ractor_rails_shim/callbacks/dependent_association_transport.rb
Instance Method Summary collapse
-
#after(_context, _kind) ⇒ Object
Dependent cascades are a before_destroy concern; nothing runs after.
-
#applies_to?(kind) ⇒ Boolean
This transport ONLY owns the
:destroykind. -
#before(context, kind) ⇒ Object
Re-drive every dependent association the record's class declared, BEFORE the record itself is deleted (matching the before_destroy order).
-
#initialize(source:) ⇒ DependentAssociationTransport
constructor
source: a Hash { class_name => [entry, …] } as described above, OR a callable returning that Hash (resolves the shareable constant lazily at replay time in a worker).
- #source ⇒ Object
Constructor Details
#initialize(source:) ⇒ DependentAssociationTransport
source: a Hash { class_name => [entry, …] } as described above, OR a callable returning that Hash (resolves the shareable constant lazily at replay time in a worker).
27 28 29 |
# File 'lib/ractor_rails_shim/callbacks/dependent_association_transport.rb', line 27 def initialize(source:) @source = source end |
Instance Method Details
#after(_context, _kind) ⇒ Object
Dependent cascades are a before_destroy concern; nothing runs after.
60 61 62 |
# File 'lib/ractor_rails_shim/callbacks/dependent_association_transport.rb', line 60 def after(_context, _kind) nil end |
#applies_to?(kind) ⇒ Boolean
This transport ONLY owns the :destroy kind. (The symbolic transport
also applies to :destroy for app before_destroy methods; both run.)
42 43 44 |
# File 'lib/ractor_rails_shim/callbacks/dependent_association_transport.rb', line 42 def applies_to?(kind) kind == :destroy end |
#before(context, kind) ⇒ Object
Re-drive every dependent association the record's class declared, BEFORE the record itself is deleted (matching the before_destroy order).
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ractor_rails_shim/callbacks/dependent_association_transport.rb', line 48 def before(context, kind) return unless kind == :destroy table = source entries = table && table[class_name_of(context)] return unless entries entries.each do |entry| assoc = association_of(context, entry[:name]) assoc.handle_dependency if assoc && assoc.respond_to?(:handle_dependency) end end |
#source ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/ractor_rails_shim/callbacks/dependent_association_transport.rb', line 31 def source s = @source return s.call if s.respond_to?(:call) return ::RactorRailsShim.const_get(s) if s.is_a?(::Symbol) s rescue StandardError nil end |