Class: SitemapGenerator::FileAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/sitemap_generator/adapters/file_adapter.rb

Instance Method Summary collapse

Instance Method Details

#gzip(stream, data) ⇒ Object



15
16
17
18
19
# File 'lib/sitemap_generator/adapters/file_adapter.rb', line 15

def gzip(stream, data)
  gz = Zlib::GzipWriter.new(stream)
  gz.write data
  gz.close
end

#write(location, raw_data) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/sitemap_generator/adapters/file_adapter.rb', line 3

def write(location, raw_data)
  # Ensure that the directory exists
  dir = location.directory
  if !File.exists?(dir)
    FileUtils.mkdir_p(dir)
  elsif !File.directory?(dir)
    raise SitemapError.new("#{dir} should be a directory!")
  end

  gzip(open(location.path, 'wb'), raw_data)
end