lib/big_sitemap.rb in big_sitemap-0.8.1 vs lib/big_sitemap.rb in big_sitemap-0.8.2
- old
+ new
@@ -20,11 +20,11 @@
COUNT_METHODS = [:count_for_sitemap, :count]
FIND_METHODS = [:find_for_sitemap, :all]
TIMESTAMP_METHODS = [:updated_at, :updated_on, :updated, :created_at, :created_on, :created]
PARAM_METHODS = [:to_param, :id]
- def initialize(options)
+ def initialize(options={})
@options = DEFAULTS.merge options
@default_url_options = options.delete(:default_url_options) || {}
if @options[:max_per_sitemap] <= 1
@@ -54,19 +54,28 @@
@file_path = "#{@options[:document_root]}/#{strip_leading_slash(@options[:path])}"
Dir.mkdir(@file_path) unless File.exists? @file_path
@sources = []
+ @models = []
@sitemap_files = []
end
def add(model, options={})
+ @models << model
+
+ filename_suffix = @models.count(model) - 1
+
options[:path] ||= table_name(model)
options[:filename] ||= file_name(model)
options[:primary_column] ||= 'id' if model.new.respond_to?('id')
options[:partial_update] = @options[:partial_update] && options[:partial_update] != false
+
+ options[:filename] << "_#{filename_suffix}" unless filename_suffix == 0
+
@sources << [model, options.dup]
+
self
end
def add_static(url, time = nil, frequency = nil, priority = nil)
@static_pages ||= []
@@ -80,11 +89,11 @@
yield
ensure
unlock!
end
rescue Errno::EACCES => e
- STDERR.puts "Lockfile exists"
+ STDERR.puts 'Lockfile exists' if $VERBOSE
end
def table_name(model)
model.table_name
end
@@ -329,11 +338,11 @@
class BigSitemapRails < BigSitemap
include ActionController::UrlWriter if defined? Rails
- def initialize(options)
+ def initialize(options={})
require 'action_controller'
super options.merge(:default_url_options => default_url_options)
end
@@ -344,10 +353,10 @@
class BigSitemapMerb < BigSitemap
- def initialize(options)
+ def initialize(options={})
require 'extlib'
super
end
def document_root
\ No newline at end of file