lib/massive_sitemap/builder/rotating.rb in massive_sitemap-2.0.0.rc2 vs lib/massive_sitemap/builder/rotating.rb in massive_sitemap-2.0.0.rc3
- old
+ new
@@ -4,35 +4,38 @@
module MassiveSitemap
module Builder
class Rotating < Base
NUM_URLS = 1..50_000
+ OPTS = Base::OPTS.merge(
+ :max_per_sitemap => NUM_URLS.max
+ )
+
def initialize(writer, options = {}, &block)
- @max_urls = options[:max_per_sitemap] || NUM_URLS.max
@rotations = 0
- @urls = 0
+ @urls = 0
- unless NUM_URLS.member?(@max_urls)
+ if options[:max_per_sitemap] && !NUM_URLS.member?(options[:max_per_sitemap])
raise ArgumentError, %Q(":max_per_sitemap" must be greater than #{NUM_URLS.min} and smaller than #{NUM_URLS.max})
end
super
end
# On rotation, close current file, and reopen a new one
# with same file name but -<counter> appendend
def init!(&block)
unless @writer.inited?
- @urls = 0
+ @urls = 0
filename = filename_with_rotation(@writer.options[:filename], @rotations)
@rotations += 1
@writer.init! :filename => filename
header!(&block)
end
end
def add_url!(location, attrs = {})
- if @urls >= @max_urls
+ if @urls >= @options[:max_per_sitemap]
close!
end
super
@urls += 1
end