class Distyll

Public Class Methods

run(base_models, created_since) click to toggle source
# File lib/distyll.rb, line 3
def self.run(base_models, created_since)
  @model_profiles = Hash.new

  base_models.each do |model|
    if @model_profiles[model].nil?
      base_profile = DistyllModelProfile.new(model, true)
      base_profile.load_ids_by_timestamp(created_since)
      @model_profiles[model] = base_profile
    end
  end

  prior_count = -1
  while prior_count != current_count
    prior_count = current_count
    @model_profiles.each_value &:demote_current_ids

    # .dup is necessary here because of Ruby 1.9's "RuntimeError: can't add a new
    #   key into hash during iteration" encountered in self.find_or_store_profile.
    @model_profiles.dup.each_value do |profile|
      unless profile.prior_ids.blank?
        profile.associations.each do |a|
          # We DO want to make the associated profile continue to traverse has_manies if
          #   (a) The current profile traverses has_manies AND
          #   (b) The association we're about to traverse is a has_many.
          contagious_has_many = profile.include_has_many && !(a.belongs_to? || a.has_and_belongs_to_many?)

          find_or_store_profile(a.klass, contagious_has_many).load_ids(profile.get_new_associated_ids(a))
        end
      end
    end
  end

  @model_profiles.each_value do |profile|
    profile.copy_records
  end
end

Private Class Methods

current_count() click to toggle source
# File lib/distyll.rb, line 43
def self.current_count
  @model_profiles.each_value.sum &:get_id_count
end
find_or_store_profile(model, include_has_many) click to toggle source
# File lib/distyll.rb, line 47
def self.find_or_store_profile(model, include_has_many)
  @model_profiles[model] ||= DistyllModelProfile.new(model, include_has_many)
end