Skip to content

Commit

Permalink
Fix possible double require of classes
Browse files Browse the repository at this point in the history
When loading environment berfor tire:import:all, it is possible that
models are already loaded when tire tries to load them. This can cause
redefinition of constants and all other kind of havoc.

This fix first tries to constantize the models to see if they are
already loaded before trying to require them.

See issue karmi#744 for discussion.
  • Loading branch information
felixbuenemann committed Sep 18, 2013
1 parent 1341e9e commit eedc0a2
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/tire/tasks.rb
Expand Up @@ -121,10 +121,12 @@ def import_model(index, klass, params)

puts "[IMPORT] Loading models from: #{dir}"
Dir.glob(File.join("#{dir}/**/*.rb")).each do |path|
require path

model_filename = path[/#{Regexp.escape(dir.to_s)}\/([^\.]+).rb/, 1]
klass = model_filename.camelize.constantize
begin
klass = model_filename.camelize.constantize
rescue NameError
require(path) ? retry : raise
end

# Skip if the class doesn't have Tire integration
next unless klass.respond_to?(:tire)
Expand Down

0 comments on commit eedc0a2

Please sign in to comment.