123456789_123456789_123456789_123456789_123456789_

Class: ActiveStorage::Attached::Changes::DetachOne

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: activestorage/lib/active_storage/attached/changes/detach_one.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(name, record, attachment) ⇒ DetachOne

[ GitHub ]

  
# File 'activestorage/lib/active_storage/attached/changes/detach_one.rb', line 7

def initialize(name, record, attachment)
  @name, @record, @attachment = name, record, attachment
end

Instance Attribute Details

#attachment (readonly)

[ GitHub ]

  
# File 'activestorage/lib/active_storage/attached/changes/detach_one.rb', line 5

attr_reader :name, :record, :attachment

#name (readonly)

[ GitHub ]

  
# File 'activestorage/lib/active_storage/attached/changes/detach_one.rb', line 5

attr_reader :name, :record, :attachment

#record (readonly)

[ GitHub ]

  
# File 'activestorage/lib/active_storage/attached/changes/detach_one.rb', line 5

attr_reader :name, :record, :attachment

Instance Method Details

#detach

[ GitHub ]

  
# File 'activestorage/lib/active_storage/attached/changes/detach_one.rb', line 11

def detach
  if attachment.present?
    attachment.delete
    reset
  end
end

#reset (private)

[ GitHub ]

  
# File 'activestorage/lib/active_storage/attached/changes/detach_one.rb', line 19

def reset
  record.attachment_changes.delete(name)
  record.public_send("#{name}_attachment=", nil)
end