Sha256: 3563c0d51909fb8c115e4bd68833bbf5f92f6d3577ae69d65d4025c88d2c256c

Contents?: true

Size: 941 Bytes

Versions: 1

Compression:

Stored size: 941 Bytes

Contents

module Paperclip
  module InstanceMethods #:nodoc:
    def attachment_for name
      @_paperclip_attachments ||= {}
      @_paperclip_attachments[name] ||= Attachment.new(name, self, self.class.attachment_definitions[name])
    end

    def each_attachment
      self.class.attachment_definitions.each do |name, definition|
        yield(name, attachment_for(name))
      end
    end

    def save_attached_files
      Paperclip.log("Saving attachments.")
      each_attachment do |name, attachment|
        attachment.send(:save)
      end
    end

    def destroy_attached_files
      Paperclip.log("Deleting attachments.")
      each_attachment do |name, attachment|
        attachment.send(:flush_deletes)
      end
    end

    def prepare_for_destroy
      Paperclip.log("Scheduling attachments for deletion.")
      each_attachment do |name, attachment|
        attachment.send(:queue_existing_for_delete)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
paperclip-3.0.2 lib/paperclip/instance_methods.rb