class MiddlemanSimpleThumbnailer::ImageStore
Attributes
tmp_path[R]
Public Class Methods
new()
click to toggle source
# File lib/middleman-simple-thumbnailer/image_store.rb, line 7 def initialize @tmp_path = Dir::Tmpname.create('thumbnail', nil) {} end
Public Instance Methods
delete()
click to toggle source
# File lib/middleman-simple-thumbnailer/image_store.rb, line 37 def delete File.delete(@tmp_path) if File.exist?(@tmp_path) end
each() { |*store_entry| ... }
click to toggle source
# File lib/middleman-simple-thumbnailer/image_store.rb, line 26 def each return unless File.exist?(@tmp_path) File.open(@tmp_path, "r") do |f| f.flock(File::LOCK_SH) resized_images = f.size > 0 ? Marshal.load(f) : {} resized_images.values.each do |store_entry| yield *store_entry end end end
store(img_path, resize_to)
click to toggle source
# File lib/middleman-simple-thumbnailer/image_store.rb, line 11 def store(img_path, resize_to) File.open(@tmp_path, File::RDWR|File::CREAT, 0644) do |f| f.flock(File::LOCK_EX) resized_images = f.size > 0 ? Marshal.load(f) : {} file_key = "#{img_path}.#{resize_to}" if ! resized_images.has_key?(file_key) resized_images[file_key] = [img_path, resize_to] f.rewind Marshal.dump(resized_images,f) f.flush f.truncate(f.pos) end end end