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
-
#write(location, raw_data) ⇒ Object
Write data to a file.
Instance Method Details
#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 29 |
# File 'lib/sitemap_generator/adapters/file_adapter.rb', line 13 def write(location, raw_data) # rubocop:disable Metrics/MethodLength # Ensure that the directory exists dir = location.directory if !File.exist?(dir) FileUtils.mkdir_p(dir) elsif !File.directory?(dir) raise SitemapError, "#{dir} should be a directory!" end File.open(location.path, 'wb') do |stream| if location.gzip? gzip(stream, raw_data) else stream.write raw_data end end end |