Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Make methods chainable

  • Loading branch information...
commit 2a2f23a42f957edb5e315f591b9f561e0ef30e5b 1 parent bdb13f4
Alex Rabarts alexrabarts authored
8 README.markdown
Source Rendered
@@ -14,13 +14,17 @@ BigSitemap is a Sitemap generator specifically designed for large sites (althoug
14 14 The minimum required to generate a sitemap is:
15 15
16 16 <pre>
  17 + BigSitemap.new(:base_url => 'http://example.com').add(:model => MyModel, :path => 'my_controller').generate
  18 +</pre>
  19 +
  20 +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:
  21 +
  22 +<pre>
17 23 sitemap = BigSitemap.new(:base_url => 'http://example.com')
18 24 sitemap.add(:model => MyModel, :path => 'my_controller')
19 25 sitemap.generate
20 26 </pre>
21 27
22   -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.
23   -
24 28 ### Find Methods
25 29
26 30 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.
3  lib/big_sitemap.rb
@@ -43,6 +43,7 @@ def initialize(options)
43 43 def add(options)
44 44 raise ArgumentError, ':model and :path options must be provided' unless options[:model] && options[:path]
45 45 @sources << options
  46 + self # Chainable
46 47 end
47 48
48 49 def clean
@@ -52,6 +53,7 @@ def clean
52 53 File.delete(f) if File.file?(f)
53 54 end
54 55 end
  56 + self # Chainable
55 57 end
56 58
57 59 def generate
@@ -121,6 +123,7 @@ def generate
121 123
122 124 generate_sitemap_index
123 125 ping_search_engines
  126 + self # Chainable
124 127 end
125 128
126 129 private
21 test/big_sitemap_test.rb
@@ -114,6 +114,27 @@ def teardown
114 114 end
115 115 end
116 116
  117 + context 'add method' do
  118 + should 'be chainable' do
  119 + create_sitemap
  120 + assert_equal BigSitemap, @sitemap.add({:model => TestModel, :path => 'test_controller'}).class
  121 + end
  122 + end
  123 +
  124 + context 'clean method' do
  125 + should 'be chainable' do
  126 + create_sitemap
  127 + assert_equal BigSitemap, @sitemap.clean.class
  128 + end
  129 + end
  130 +
  131 + context 'generate method' do
  132 + should 'be chainable' do
  133 + create_sitemap
  134 + assert_equal BigSitemap, @sitemap.generate.class
  135 + end
  136 + end
  137 +
117 138 private
118 139 def delete_tmp_files
119 140 FileUtils.rm_rf(sitemaps_dir)

0 comments on commit 2a2f23a

Please sign in to comment.
Something went wrong with that request. Please try again.