lib/mongoid_schema_dump.rb
#Computes all paths to reference class
Computes all paths to reference class
Computes all paths to reference class
def paths_to_klass(klass, reference_klass)
    displayed_for_klass = false
    paths = []
    to_visit = [[klass, []]]
    current_klass = klass
    loop do
      current_klass, path = to_visit.pop 
      break unless current_klass  
      path << current_klass
      if current_klass.to_s == reference_klass 
        paths << path
        next
      end
      break if current_klass.nil?
      next_klasses = all_belongs_to(current_klass)
      next_klasses.each do |next_klass|
        next if next_klass == current_klass.to_s
        to_visit << [next_klass.constantize, path.clone]
      end
      break if to_visit.empty?
    end
    return paths 
  end
def paths_to_klass ( klass , reference_klass ) displayed_for_klass = false paths = [ ] to_visit = [ [ klass , [ ] ] ] current_klass = klass loop do current_klass , path = to_visit . pop break unless current_klass path << current_klass if current_klass . to_s == reference_klass paths << path next end break if current_klass . nil? next_klasses = all_belongs_to ( current_klass ) next_klasses . each do | next_klass | next if next_klass == current_klass . to_s to_visit << [ next_klass . constantize , path . clone ] end break if to_visit . empty? end return paths end
Computes all paths to reference class
Computes all paths to reference class
#FIFO
klass
reference_klass