Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make methods chainable

  • Loading branch information...
commit 2a2f23a42f957edb5e315f591b9f561e0ef30e5b 1 parent bdb13f4
@alexrabarts alexrabarts authored
Showing with 30 additions and 2 deletions.
  1. +6 −2 README.markdown
  2. +3 −0  lib/big_sitemap.rb
  3. +21 −0 test/big_sitemap_test.rb
View
8 README.markdown
@@ -14,13 +14,17 @@ BigSitemap is a Sitemap generator specifically designed for large sites (althoug
The minimum required to generate a sitemap is:
<pre>
+ BigSitemap.new(:base_url => 'http://example.com').add(:model => MyModel, :path => 'my_controller').generate
+</pre>
+
+You can put this in a rake/thor task and create a cron job to run it periodically. It should be enough for most Rails/Merb applications. Note that the methods are chainable, although you can call them on an instance variable if you prefer:
+
+<pre>
sitemap = BigSitemap.new(:base_url => 'http://example.com')
sitemap.add(:model => MyModel, :path => 'my_controller')
sitemap.generate
</pre>
-You can put this in a rake/thor task and create a cron job to run it periodically. It should be enough for most Rails/Merb applications.
-
### Find Methods
Your models must provide either a <code>find_for_sitemap</code> or <code>all</code> class method that returns the instances that are to be included in the sitemap. Additionally, you models must provide a <code>count_for_sitemap</code> or <code>count</code> class method that returns a count of the instances to be included. If you're using ActiveRecord (Rails) or DataMapper then <code>all</code> and <code>count</code> are already provided and you don't need to do anything unless you want to include a subset of records. If you provide your own <code>find_for_sitemap</code> or <code>all</code> method then it should be able to handle the <code>:offset</code> and <code>:limit</code> options, in the same way that ActiveRecord and DataMapper handle them. This is especially important if you have more than 50,000 URLs.
View
3  lib/big_sitemap.rb
@@ -43,6 +43,7 @@ def initialize(options)
def add(options)
raise ArgumentError, ':model and :path options must be provided' unless options[:model] && options[:path]
@sources << options
+ self # Chainable
end
def clean
@@ -52,6 +53,7 @@ def clean
File.delete(f) if File.file?(f)
end
end
+ self # Chainable
end
def generate
@@ -121,6 +123,7 @@ def generate
generate_sitemap_index
ping_search_engines
+ self # Chainable
end
private
View
21 test/big_sitemap_test.rb
@@ -114,6 +114,27 @@ def teardown
end
end
+ context 'add method' do
+ should 'be chainable' do
+ create_sitemap
+ assert_equal BigSitemap, @sitemap.add({:model => TestModel, :path => 'test_controller'}).class
+ end
+ end
+
+ context 'clean method' do
+ should 'be chainable' do
+ create_sitemap
+ assert_equal BigSitemap, @sitemap.clean.class
+ end
+ end
+
+ context 'generate method' do
+ should 'be chainable' do
+ create_sitemap
+ assert_equal BigSitemap, @sitemap.generate.class
+ end
+ end
+
private
def delete_tmp_files
FileUtils.rm_rf(sitemaps_dir)
Please sign in to comment.
Something went wrong with that request. Please try again.