Skip to content

Commit

Permalink
Changed find_models method to support sub directories
Browse files Browse the repository at this point in the history
  • Loading branch information
Danny Hawkins committed Jan 7, 2010
1 parent d39d376 commit a1a7218
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/sitemap_generator/generator.rb
Expand Up @@ -19,12 +19,13 @@ def initialize(filename = "#{RAILS_ROOT}/public/sitemap.xml")

def find_models
models = []

files = Dir.glob(File.join(RAILS_ROOT, 'app', 'models', '*.rb')).delete_if {|c| c =~ /observer\.rb/ } #{|c| c < ActiveRecord::Base== false}

files.each do |file|
model_path = File.join(RAILS_ROOT, 'app', 'models')
files = Find.find(model_path) do |file|
next unless file[-3..-1] == '.rb'
next if file =~ /observer.rb/
file.gsub!(model_path,'')
# Get the class from the filename
model = file.split('/').last[0..-4].classify.constantize
model = file.split('/').map{|f| f.gsub('.rb','').classify unless f.empty?}.compact.join('::').constantize
# Skip classes that don't have any sitemap options
next if !model.methods.include?('sitemap_options') || model.sitemap_options == nil

Expand Down

0 comments on commit a1a7218

Please sign in to comment.