Module: MobilityActiveStorage::FallbackAttached

Defined in:
lib/mobility_active_storage/fallback_attached.rb,
sig/mobility_active_storage.rbs

Overview

Attached proxies used when a read resolves through a fallback locale.

Reads (+attached?+, filename, url, iteration) resolve to the fallback locale's attachment, but every write -- attach, purge, purge_later, detach -- stays bound to the locale actually being read. Without that split, product.document.attach(file) under a fallback would overwrite the fallback locale's file instead of creating one for the current locale.

The classes are built lazily: Active Storage's classes are autoloaded by its engine, which has not necessarily run at the point this gem is required from a Gemfile.

Constant Summary collapse

BUILD_MUTEX =

Guards the lazy build. Two threads racing here would both const_set, emitting an "already initialized constant" warning and handing callers structurally distinct classes, which would then fail each other's is_a? checks.

Mutex.new

Class Method Summary collapse

Class Method Details

.manyClass

Returns:

  • (Class)


25
26
27
# File 'lib/mobility_active_storage/fallback_attached.rb', line 25

def many
  @many || BUILD_MUTEX.synchronize { @many ||= const_set(:Many, build_many) }
end

.oneClass

Returns:

  • (Class)


21
22
23
# File 'lib/mobility_active_storage/fallback_attached.rb', line 21

def one
  @one || BUILD_MUTEX.synchronize { @one ||= const_set(:One, build_one) }
end