class TreeClimber
Attributes
baton[R]
model[R]
Public Class Methods
new(model, baton={})
click to toggle source
# File lib/dumper.rb, line 67 def initialize(model, baton={}) @model = model @baton = baton initialize_baton end
Public Instance Methods
climb_with(monkey)
click to toggle source
# File lib/dumper.rb, line 83 def climb_with(monkey) return if baton[:ignore_models].include?(model.class) table_name = model.class.respond_to?(:table_name) ? model.class.table_name : nil return if baton[:ignore_tables].include?(table_name) || table_name.nil? if baton[:dumped_ids][model.class].include?(model.id) return else baton[:dumped_ids][model.class] << model.id end bananas = [] bananas << monkey.harvest(model, baton) STDERR << "Getting banana #{model.class}:#{model.id}\n" if baton[:debug] if baton[:level] baton[:current_level] -= 1 end if !baton[:ignore_associations_for].include?(model.class) and baton[:current_level] >= 0 model.class.reflect_on_all_associations.each do |assoc| assoc_value = model.send(assoc.name) if assoc_value unless assoc_value.is_a? Array leafs = [ assoc_value ] else leafs = assoc_value end leafs.each do |leaf| bananas << TreeClimber.new(leaf, baton).climb_with(monkey) end end end end monkey.sort_out_bananas(bananas.flatten.compact) end
initialize_baton()
click to toggle source
# File lib/dumper.rb, line 73 def initialize_baton baton[:ignore_associations_for] ||= [] baton[:ignore_models] ||= [] baton[:ignore_tables] ||= [] baton[:dumped_ids] ||= Hash.new { |hsh,key| hsh[key] = Array.new } baton[:current_level] ||= baton[:level].to_i baton[:debug] ||= false baton[:add_deletes] ||= false end