Sha256: e039b4588857942b3758de28d4ee5e5852feadac2524c6c62c2a621b860f3f9b

Contents?: true

Size: 512 Bytes

Versions: 71

Compression:

Stored size: 512 Bytes

Contents

# frozen_string_literal: true

module ActiveStorage
  class Attached::Changes::DetachOne # :nodoc:
    attr_reader :name, :record, :attachment

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

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

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

Version data entries

71 entries across 68 versions & 6 rubygems

Version Path
activestorage-8.0.0 lib/active_storage/attached/changes/detach_one.rb
activestorage-7.2.2 lib/active_storage/attached/changes/detach_one.rb
activestorage-7.1.5 lib/active_storage/attached/changes/detach_one.rb
activestorage-8.0.0.rc2 lib/active_storage/attached/changes/detach_one.rb
activestorage-7.2.1.2 lib/active_storage/attached/changes/detach_one.rb
activestorage-7.1.4.2 lib/active_storage/attached/changes/detach_one.rb
activestorage-7.0.8.6 lib/active_storage/attached/changes/detach_one.rb
activestorage-8.0.0.rc1 lib/active_storage/attached/changes/detach_one.rb
activestorage-7.2.1.1 lib/active_storage/attached/changes/detach_one.rb
activestorage-7.1.4.1 lib/active_storage/attached/changes/detach_one.rb
activestorage-7.0.8.5 lib/active_storage/attached/changes/detach_one.rb
activestorage-8.0.0.beta1 lib/active_storage/attached/changes/detach_one.rb
omg-activestorage-8.0.0.alpha9 lib/active_storage/attached/changes/detach_one.rb
omg-activestorage-8.0.0.alpha8 lib/active_storage/attached/changes/detach_one.rb
omg-activestorage-8.0.0.alpha7 lib/active_storage/attached/changes/detach_one.rb
omg-activestorage-8.0.0.alpha4 lib/active_storage/attached/changes/detach_one.rb
omg-activestorage-8.0.0.alpha3 lib/active_storage/attached/changes/detach_one.rb
activestorage-7.1.4 lib/active_storage/attached/changes/detach_one.rb
activestorage-7.2.1 lib/active_storage/attached/changes/detach_one.rb
activestorage-7.2.0 lib/active_storage/attached/changes/detach_one.rb