Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add clean method

  • Loading branch information...
commit b5950aaadf2a72c67676a34f2e08d864312e6e70 1 parent 1bc188a
@alexrabarts alexrabarts authored
View
4 README.markdown
@@ -48,6 +48,10 @@ By default, the sitemap files are created under <code>/sitemaps</code>. You can
BigSitemap.new(:base_url => 'http://example.com', :path => 'google-sitemaps') # places Sitemaps under /google-sitemaps
</pre>
+### Cleaning the Sitemaps Directory
+
+Calling the <code>clean</code> method will remove all files from the Sitemaps directory.
+
### Maximum Number of URLs
Sitemaps will be split across several files if more than 50,000 records are returned. You can customize this limit with the <code>:max_per_sitemap</code> option:
View
9 lib/big_sitemap.rb
@@ -45,6 +45,15 @@ def add(options)
@sources << options
end
+ def clean
+ unless @file_path.nil?
+ Dir.foreach(@file_path) do |f|
+ f = "#{@file_path}/#{f}"
+ File.delete(f) if File.file?(f)
+ end
+ end
+ end
+
def generate
@sources.each do |source|
klass = source[:model]
View
7 test/big_sitemap_test.rb
@@ -35,6 +35,13 @@ def teardown
assert !File.exists?(third_sitemaps_model_file), "#{third_sitemaps_model_file} does not exist"
end
+ should 'clean all sitemap files' do
+ generate_sitemap_files
+ assert Dir.entries(sitemaps_dir).size > 2, "#{sitemaps_dir} is not empty" # ['.', '..'].size == 2
+ @sitemap.clean
+ assert_equal 2, Dir.entries(sitemaps_dir).size, "#{sitemaps_dir} is empty"
+ end
+
context 'Sitemap index file' do
should 'contain one sitemapindex element' do
generate_sitemap_files
Please sign in to comment.
Something went wrong with that request. Please try again.