Class: TypedEAV::Engine

Inherits:
Rails::Engine
  • Object
show all
Defined in:
lib/typed_eav/engine.rb

Class Method Summary collapse

Class Method Details

.register_attachment_associations!Object

Conditionally register the :attachment has_one_attached association on TypedEAV::Value. Idempotent β€” safe to call multiple times. The idempotency guard (β€˜@attachment_registered`) prevents double- registration when specs invoke the seam in addition to the engine boot path. Without the guard, AR’s has_one_attached macro would redefine the association methods (technically harmless but generates RuntimeError noise on duplicate declaration in newer AS versions).

Returns truthy on first successful registration, falsy when AS is unloaded or the association is already registered. The return is not part of the public contract β€” specs that care about the registration outcome inspect TypedEAV::Value.reflect_on_attachment directly.



129
130
131
132
133
134
135
# File 'lib/typed_eav/engine.rb', line 129

def self.register_attachment_associations!
  return false unless defined?(::ActiveStorage::Blob)
  return false if @attachment_registered

  TypedEAV::Value.has_one_attached :attachment
  @attachment_registered = true
end