Module: ActiveStorage::Attached::Model

Extended by:
ActiveSupport::Concern
Defined in:
activestorage/lib/active_storage/attached/model.rb

Overview

Active Storage Attached Model

Provides the class-level DSL for declaring an Active Record model’s attachments.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ActiveSupport::Concern

append_features, class_methods, extended, included, prepend_features, prepended

Class Method Details

.validate_service_configuration(service_name, model_class, association_name) ⇒ Object

:nodoc:



288
289
290
291
292
293
294
295
296
# File 'activestorage/lib/active_storage/attached/model.rb', line 288

def validate_service_configuration(service_name, model_class, association_name) # :nodoc:
  if service_name
    ActiveStorage::Blob.services.fetch(service_name) do
      raise ArgumentError, "Cannot configure service #{service_name.inspect} for #{model_class}##{association_name}"
    end
  else
    validate_global_service_configuration(model_class)
  end
end

Instance Method Details

#attachment_changesObject

:nodoc:



306
307
308
# File 'activestorage/lib/active_storage/attached/model.rb', line 306

def attachment_changes # :nodoc:
  @attachment_changes ||= {}
end

#changed_for_autosave?Boolean

:nodoc:

Returns:

  • (Boolean)


310
311
312
# File 'activestorage/lib/active_storage/attached/model.rb', line 310

def changed_for_autosave? # :nodoc:
  super || attachment_changes.any?
end

#initialize_dupObject

:nodoc:



314
315
316
317
318
# File 'activestorage/lib/active_storage/attached/model.rb', line 314

def initialize_dup(*) # :nodoc:
  super
  @active_storage_attached = nil
  @attachment_changes = nil
end

#reloadObject

:nodoc:



320
321
322
# File 'activestorage/lib/active_storage/attached/model.rb', line 320

def reload(*) # :nodoc:
  super.tap { @attachment_changes = nil }
end