class Paperclip::AttachmentAdapter
Public Class Methods
new(target, options = {})
click to toggle source
Calls superclass method
Paperclip::AbstractAdapter::new
# File lib/paperclip/io_adapters/attachment_adapter.rb, line 9 def initialize(target, options = {}) super @target, @style = case target when Paperclip::Attachment [target, :original] when Paperclip::Style [target.attachment, target.name] end cache_current_values end
register()
click to toggle source
# File lib/paperclip/io_adapters/attachment_adapter.rb, line 3 def self.register Paperclip.io_adapters.register self do |target| Paperclip::Attachment === target || Paperclip::Style === target end end
Private Instance Methods
cache_current_values()
click to toggle source
# File lib/paperclip/io_adapters/attachment_adapter.rb, line 23 def cache_current_values self.original_filename = @target.original_filename @content_type = @target.content_type @tempfile = copy_to_tempfile(@target) @size = @tempfile.size || @target.size end
copy_to_tempfile(source)
click to toggle source
# File lib/paperclip/io_adapters/attachment_adapter.rb, line 30 def copy_to_tempfile(source) if source.staged? link_or_copy_file(source.staged_path(@style), destination.path) else begin source.copy_to_local_file(@style, destination.path) rescue Errno::EACCES # clean up lingering tempfile if we cannot access source file destination.close(true) raise end end destination end