Class: Imprenta::Storage::File

Inherits:
Object
  • Object
show all
Defined in:
lib/imprenta/storage/file.rb

Instance Method Summary collapse

Instance Method Details

#persist(content, id, extension = '.html', gzip = Zlib::BEST_COMPRESSION) ⇒ Object

This methods come from action_pack/cache_page’ github.com/rails/actionpack-page_caching We didn’t need the whole gem. So I decided to get just what we need :)



8
9
10
11
12
13
14
15
# File 'lib/imprenta/storage/file.rb', line 8

def persist(content, id, extension = '.html', gzip = Zlib::BEST_COMPRESSION)
  path = path_for_id(id, extension)
  FileUtils.makedirs(::File.dirname(path))
  ::File.open(path, 'wb+') { |f| f.write(content) }
  if gzip
    Zlib::GzipWriter.open(path + '.gz', gzip) { |f| f.write(content) }
  end
end