Sha256: 0cd05a13611c199f1f7bd0f92eed8b5a60088e67936a7bfbb32bb28053224ac0
Contents?: true
Size: 1.41 KB
Versions: 1
Compression:
Stored size: 1.41 KB
Contents
require 'fileutils' require "massive_sitemap/writer/base" # Write into File module MassiveSitemap module Writer class File < Base class FileExistsException < IOError; end OPTS = Base::OPTS.merge( :document_full => '.', :force_overwrite => false, :filename => "sitemap.xml", :index_filename => "sitemap_index.xml", ) def open_stream dir = ::File.dirname(tmp_filename) Dir.mkdir(dir) unless ::File.exists?(dir) ::File.open(tmp_filename, 'w:ASCII-8BIT') end def close_stream(stream) stream.close # Move from tmp_file into acutal file ::File.delete(filename) if ::File.exists?(filename) ::File.rename(tmp_filename, filename) end def init? if !options[:force_overwrite] && ::File.exists?(filename) raise FileExistsException, "Can not create file: #{filename} exits" end true end def streams files.map do |path| next if path.include?(options[:index_filename]) [::File.basename(path), ::File.stat(path).mtime] end.compact end private def filename ::File.join options[:document_full], options[:filename] end def tmp_filename filename + ".tmp" end def files Dir[::File.join(options[:document_full], "*.xml")] end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
massive_sitemap-2.0.0.rc2 | lib/massive_sitemap/writer/file.rb |