Class: SitemapGenerator::FileAdapter
- Inherits:
-
Object
- Object
- SitemapGenerator::FileAdapter
- Defined in:
- lib/sitemap_generator/adapters/file_adapter.rb
Overview
Class for writing out data to a file.
Instance Method Summary collapse
-
#gzip(stream, data) ⇒ Object
Write ‘data` to a stream, passing the data through a GzipWriter to compress it.
-
#plain(stream, data) ⇒ Object
Write ‘data` to a stream as is.
-
#write(location, raw_data) ⇒ Object
Write data to a file.
Instance Method Details
#gzip(stream, data) ⇒ Object
Write ‘data` to a stream, passing the data through a GzipWriter to compress it.
32 33 34 35 36 |
# File 'lib/sitemap_generator/adapters/file_adapter.rb', line 32 def gzip(stream, data) gz = Zlib::GzipWriter.new(stream) gz.write data gz.close end |
#plain(stream, data) ⇒ Object
Write ‘data` to a stream as is.
39 40 41 42 |
# File 'lib/sitemap_generator/adapters/file_adapter.rb', line 39 def plain(stream, data) stream.write data stream.close end |
#write(location, raw_data) ⇒ Object
Write data to a file.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/sitemap_generator/adapters/file_adapter.rb', line 13 def write(location, raw_data) # Ensure that the directory exists dir = location.directory if !File.exist?(dir) FileUtils.mkdir_p(dir) elsif !File.directory?(dir) raise SitemapError.new("#{dir} should be a directory!") end stream = open(location.path, 'wb') if location.path.to_s =~ /.gz$/ gzip(stream, raw_data) else plain(stream, raw_data) end end |