Skip to content

Commit

Permalink
only load extlib if it's not rails
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Bielohlawek committed Dec 7, 2010
1 parent 3d33097 commit 84db571
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions lib/big_sitemap.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
require 'uri'
require 'big_sitemap/builder'
require 'extlib'
require 'action_controller' if defined? Rails

if defined? Rails
require 'action_controller'
else
require 'extlib'
end

class BigSitemap
DEFAULTS = {
Expand Down Expand Up @@ -69,11 +73,19 @@ def initialize(options)
end

def add(model, options={})
options[:path] ||= Extlib::Inflection.tableize(model.to_s)
options[:path] ||= table_name(model)
@sources << [model, options.dup]
return self
end

def table_name(model)
if defined? Rails
model.table_name
else
Extlib::Inflection.tableize(model.to_s)
end
end

def clean
Dir["#{@file_path}/sitemap_*.{xml,xml.gz}"].each do |file|
FileUtils.rm file
Expand All @@ -83,7 +95,7 @@ def clean

def generate
for model, options in @sources
with_sitemap(Extlib::Inflection::tableize(model.to_s)) do |sitemap|
with_sitemap(table_name(model)) do |sitemap|
count_method = pick_method(model, COUNT_METHODS)
find_method = pick_method(model, FIND_METHODS)
raise ArgumentError, "#{model} must provide a count_for_sitemap class method" if count_method.nil?
Expand Down

0 comments on commit 84db571

Please sign in to comment.