lib/massive_sitemap.rb in massive_sitemap-2.0.0.rc3 vs lib/massive_sitemap.rb in massive_sitemap-2.0.0.rc4

- old
+ new

@@ -1,9 +1,10 @@ require 'massive_sitemap/writer/file' require 'massive_sitemap/writer/gzip_file' require 'massive_sitemap/builder/rotating' require 'massive_sitemap/builder/index' +require 'massive_sitemap/lock' require 'massive_sitemap/ping' # Page at -> <url> # http://example.de/dir/ @@ -30,23 +31,29 @@ :url => nil, :indent_by => 2, } def generate(options = {}, &block) - @options = DEFAULTS.merge options + lock! do + @options = DEFAULTS.merge options - unless @options[:url] - raise ArgumentError, 'you must specify ":url" string' - end - @options[:index_url] ||= @options[:url] + unless @options[:url] + raise ArgumentError, 'you must specify ":url" string' + end + @options[:index_url] ||= @options[:url] - @options[:writer] = Writer::GzipFile if @options[:gzip] + if @options[:max_urls] && !Builder::Rotating::NUM_URLS.member?(@options[:max_urls]) + raise ArgumentError, %Q(":max_urls" must be greater than #{NUM_URLS.min} and smaller than #{NUM_URLS.max}) + end - @writer = @options[:writer].new @options - Builder::Rotating.generate(@writer, @options, &block) + @options[:writer] = Writer::GzipFile if @options[:gzip] - @writer.init!(:filename => @options[:index_filename], :force_overwrite => true) - Builder::Index.generate(@writer, @options.merge(:url => @options[:index_url])) + @writer = @options[:writer].new @options + Builder::Rotating.generate(@writer, @options, &block) + + @writer.init!(:filename => @options[:index_filename], :force_overwrite => true) + Builder::Index.generate(@writer, @options.merge(:url => @options[:index_url])) + end end module_function :generate end