Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure host ends in a slash #245

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 17 additions & 6 deletions lib/sitemap_generator/sitemap_location.rb
Expand Up @@ -9,16 +9,27 @@ class SitemapLocation < Hash

PATH_OUTPUT_WIDTH = 47 # Character width of the path in the summary lines

[:host, :adapter].each do |method|
define_method(method) do
raise SitemapGenerator::SitemapError, "No value set for #{method}" unless self[method]
self[method]
end
def assert_value(key)
raise SitemapGenerator::SitemapError, "No value set for #{key}" unless self[key]
end

def append_slash(key)
SitemapGenerator::Utilities.append_slash(self[key])
end

def adapter
assert_value(:adapter)
self[:adapter]
end

def host
assert_value(:host)
append_slash(:host)
end

[:public_path, :sitemaps_path].each do |method|
define_method(method) do
Pathname.new(SitemapGenerator::Utilities.append_slash(self[method]))
Pathname.new(append_slash(method))
end
end

Expand Down
5 changes: 5 additions & 0 deletions spec/sitemap_generator/sitemap_location_spec.rb
Expand Up @@ -35,6 +35,11 @@
}.should raise_error
end

it "should append slash to host" do
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please just keep this change and revert the others.

location = SitemapGenerator::SitemapLocation.new(:filename => nil, :namer => nil, :host => "http://www.slash.com")
location.host.should == "http://www.slash.com/"
end

it "should accept a Namer option" do
@namer = SitemapGenerator::SimpleNamer.new(:xxx)
location = SitemapGenerator::SitemapLocation.new(:namer => @namer)
Expand Down