lib/couchrest/model/utils/migrate.rb in couchrest_model-2.0.3 vs lib/couchrest/model/utils/migrate.rb in couchrest_model-2.0.4

- old
+ new

@@ -57,11 +57,11 @@ def find_models CouchRest::Model::Base.subclasses.reject{|m| m.proxy_owner_method.present?} end def find_proxying_models - CouchRest::Model::Base.subclasses.reject{|m| m.proxy_database_method.blank?} + CouchRest::Model::Base.subclasses.reject{|m| m.proxy_method_names.empty?} end def migrate_each_model(models, db = nil) callbacks = [ ] models.each do |model| @@ -73,20 +73,25 @@ end def migrate_each_proxying_model(models) callbacks = [ ] models.each do |model| - submodels = model.proxied_model_names.map{|n| n.constantize} - model.all.each do |base| - puts "Finding proxied models for #{model}: \"#{base.send(model.proxy_database_method)}\"" - callbacks += migrate_each_model(submodels, base.proxy_database) + methods = model.proxy_method_names + methods.each do |method| + puts "Finding proxied models for #{model}##{method}" + model.all.each do |obj| + proxy = obj.send(method) + callbacks += migrate_each_model([proxy.model], proxy.database) + end end end callbacks end def migrate_design(model, design, db = nil) - print "Migrating #{model.to_s}##{design.method_name}... " + print "Migrating #{model.to_s}##{design.method_name}" + print " on #{db.name}" if db + print "... " callback = design.migrate(db) do |result| puts "#{result.to_s.gsub(/_/, ' ')}" end # Return the callback hash if there is one callback ? {:design => design, :proc => callback, :db => db || model.database} : nil