Class: Mugshot::FSStorage

Inherits:
Storage
  • Object
show all
Defined in:
lib/mugshot/fs_storage.rb

Instance Method Summary collapse

Instance Method Details

#read(id) ⇒ Object



14
15
16
17
18
19
# File 'lib/mugshot/fs_storage.rb', line 14

def read(id)
  path = id_to_path(id)
  file = File.join(@root_path, path)
  return nil unless File.exist? file
  Mugshot::Image.new File.open(file)
end

#write(bin) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/mugshot/fs_storage.rb', line 4

def write(bin)
  id = asset_id
  path = id_to_path(id)
  FileUtils.mkdir_p(File.dirname(File.join(@root_path, path)))
  File.open(File.join(@root_path, path), "w") do |fw|
    fw.write(bin)
  end
  id
end