kjvarga/sitemap_generator — Issue #66: Don't modify options object given to #add
Author: korny
Created: 2012-02-29 18:30:00+00:00
State: open

This line: https://github.com/kjvarga/sitemap_generator/blob/master/lib/sitemap_generator/link_set.rb#L130 changes the given options instead of creating a new object.

The problem (other than violating the principle to never modify objects that you didn't create) is that, when I have code like this:

```ruby
default_site_options = { :changefreq => 'daily', :priority => 0.5, :lastmod => nil }.freeze

SitemapGenerator::Sitemap.create do
add some_url, default_site_options
```

it returns my default_site_options object as:

{:news=>{}, :lastmod=>nil, :priority=>0.5, :videos=>[], :images=>[], :host=>"http://www.sofatutor.com", :changefreq=>"daily"}

When I then continue adding videos:

```ruby
Video.all.each do |video|
add video.video_url, default_site_options.merge(:video => video.sitemap_tags)
end
```

the videos array fills up with more and more videos:

```
{:news=>{}, :lastmod=>nil, :priority=>0.5, :videos=>[{:gallery_loc=>"http://localhost:3000/mathematik/verschiedenes/wichtige-konstanten", :category=>"Mathematik", :publication_date=>"2009-03-09T02:47:49+01:00", :price=>nil, :uploader=>"Konstantin E", :title=>"Irrationalität der Eulerschen Zahl e", :expiration_date=>nil, :description=>"Hier wird der Beweis dafür geführt, dass die Eulersche Zahl e tatsächlich irrational, also nicht als Bruch schreibbar ist. Dieses Videos erklärt eulersche zahl e, rational, irrational, beweis und reihendarstellung. Nachhilfe in Mathematik mit Lernvideos und Testfragen findest du auf http://localhost:3000/mathematik.", :tags=>["Video", "Nachhilfe", "Lernen", "Vorbereitung", "Klausuren", "Tests", "Lernvideo", "Üben", "Lernen", "Erklärung", "Anleitung", "eulersche zahl e", "rational", "irrational", "beweis", "reihendarstellung"], :duration=>203, :content_loc=>nil, :family_friendly=>true}], :images=>[], :host=>"http://www.sofatutor.com", :changefreq=>"daily"}```
```

…which means I get a wrong sitemap (and a quite large one, too.)