lib/seed_dump/perform.rb in seed_dump-0.4.1 vs lib/seed_dump/perform.rb in seed_dump-0.4.2
- old
+ new
@@ -40,11 +40,19 @@
puts "Processing file #{f}" if @opts['debug']
# parse file name and path leading up to file name and assume the path is a module
f =~ /models\/(.*).rb/
# split path by /, camelize the constituents, and then reform as a formal class name
parts = $1.split("/").map {|x| x.camelize}
+
# Initialize nested model namespaces
- parts.clip.inject(Object) { |x, y| x.const_set(y, Module.new) }
+ parts.clip.inject(Object) do |x, y|
+ if x.const_defined?(y)
+ x.const_get(y)
+ else
+ x.const_set(y, Module.new)
+ end
+ end
+
model = parts.join("::")
require f
puts "Detected model #{model}" if @opts['debug']
@models.push model if @opts['models'].include?(model) || @opts['models'].empty?