Permalink
Browse files

Camelize strategy names appropriately.

  • Loading branch information...
judy committed Jan 14, 2014
1 parent b6b4f18 commit caea6108dc5686dd128c0c26df81554317d73653
Showing with 9 additions and 2 deletions.
  1. +9 −2 lib/database_cleaner/base.rb
@@ -126,8 +126,8 @@ def orm_module
end
def orm_strategy(strategy)
- require "database_cleaner/#{orm.to_s}/#{strategy.to_s}"
- orm_module.const_get(strategy.to_s.capitalize)
+ require "database_cleaner/#{orm}/#{strategy}"
+ orm_module.const_get(camelize(strategy))
rescue LoadError
if orm_module.respond_to? :available_strategies
raise UnknownStrategySpecified, "The '#{strategy}' strategy does not exist for the #{orm} ORM! Available strategies: #{orm_module.available_strategies.join(', ')}"
@@ -151,5 +151,12 @@ def set_default_orm_strategy
self.strategy = :truncation
end
end
+
+ private
+
+ def camelize(term)
+ string = term.to_s.sub(/^[a-z\d]*/) { $&.capitalize }
+ string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub('/', '::')
+ end
end
end

0 comments on commit caea610

Please sign in to comment.