Permalink
Browse files

added checking on dynamic loading

  • Loading branch information...
1 parent 4ecec53 commit e010291600fe6d03900afa5fcb8aa8fff88acd55 @markjeee markjeee committed Aug 22, 2010
Showing with 20 additions and 2 deletions.
  1. +20 −2 lib/palmade/camping_ext/mixins/dynamic_routes.rb
@@ -45,6 +45,7 @@ def D_with_dynamic_routes(p, m, env)
end
controllers = camping.const_get(:Controllers)
+ base = camping.const_get(:Base)
try_loading = lambda do |kname|
controller_name = "#{controllers.name}::#{kname}"
@@ -66,9 +67,26 @@ def D_with_dynamic_routes(p, m, env)
# expected klass_name, -- by default, doesn't support
# class names with numbers on them.
unless klass_name =~ /[^A-Za-z\_]/
- unless controllers.const_defined?(klass_name)
- try_loading.call(klass_name)
+ klass = nil
+
+ # this is an added measure, since i noticed sometimes,
+ # if there's another constant, a global for example,
+ # that has the same name, const_defined? will return
+ # true (i noticed this on ruby 1.9.2), even if it is not
+ # a camping controller. So the added check on
+ # repond_to?(:urls) and Base model included, is to make
+ # sure if the constant indeed is a camping
+ # controller. or probably just something
+ # else. Othwerise, we'll try to load it again, just in
+ # case. OORRRR, this could be a entirely wrong idea.
+ if controllers.const_defined?(klass_name)
+ klass = controllers.const_get(klass_name)
+ unless klass.nil?
+ klass = nil unless klass.respond_to?(:urls) && klass.include?(base)
+ end
end
+
+ try_loading.call(klass_name) if klass.nil?
end
end

0 comments on commit e010291

Please sign in to comment.