Module: Paperclip::Storage::Tmp

Defined in:
lib/paperclip/storage/tmp.rb,
lib/paperclip-storage-tmp/version.rb

Constant Summary collapse

VERSION =
"0.0.3"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.clearObject

Deletes the temporary files and releases references to them



9
10
11
12
# File 'lib/paperclip/storage/tmp.rb', line 9

def self.clear
  fs.each_value {|f| f.unlink }
  @fs = nil
end

.fsObject



4
5
6
# File 'lib/paperclip/storage/tmp.rb', line 4

def self.fs
  @fs ||= {}
end

Instance Method Details

#exists?(style_name = default_style) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/paperclip/storage/tmp.rb', line 14

def exists?(style_name = default_style)
  Tmp.fs.key?(path(style_name))
end

#flush_deletesObject



31
32
33
34
35
36
37
38
39
# File 'lib/paperclip/storage/tmp.rb', line 31

def flush_deletes
  @queued_for_delete.each do |path|
    if file = Tmp.fs.delete(path)
      file.unlink
    end
  end

  @queued_for_delete = []
end

#flush_writesObject



22
23
24
25
26
27
28
29
# File 'lib/paperclip/storage/tmp.rb', line 22

def flush_writes
  @queued_for_write.each do |style_name, file|
    Tmp.fs[path(style_name)] = to_tempfile(file)
  end

  after_flush_writes
  @queued_for_write = {}
end

#to_file(style_name = default_style) ⇒ Object



18
19
20
# File 'lib/paperclip/storage/tmp.rb', line 18

def to_file(style_name = default_style)
  @queued_for_write[style_name] || (File.new(Tmp.fs[path(style_name)], 'rb') if exists?(style_name))
end