Module: RactorRailsShim::ActiveStorageAttachedPatch::ActiveStorageServicePatch

Defined in:
lib/ractor_rails_shim/patches/active_storage.rb

Overview

ActiveStorage::Blob#service_name is normally defaulted in an after_initialize callback (self.service_name ||= self.class.service&.name). The shim's callback replay runs only captured transport filters in a worker Ractor and skips model-level after_initialize, so service_name stays nil in a worker and ActiveStorage::Blob#service raises "undefined method 'to_sym' for nil" (it does services.fetch(service_name)). Fall back to the class-configured default service name when the attribute is blank, so the service resolves without depending on the skipped callback.

Instance Method Summary collapse

Instance Method Details

#service_nameObject



131
132
133
134
135
136
137
138
# File 'lib/ractor_rails_shim/patches/active_storage.rb', line 131

def service_name
  # Read the raw attribute directly (not via the lazily-generated
  # `service_name` reader, which this prepended method would shadow and
  # break with `super`). Fall back to the class-configured default service
  # name when the attribute is blank.
  value = read_attribute(:service_name)
  value.presence || self.class.service&.name
end