Sha256: 168b88c7f23bea284c4776b14eef6ce30a59c40a6ca296c9f4ec7199a9621935

Contents?: true

Size: 1.19 KB

Versions: 123

Compression:

Stored size: 1.19 KB

Contents

class Marty::Relation
  # Given a Mcfly class (klass) and a list of classes which can
  # reference klass, returns instaces of klass which have no references.
  def self.not_referenced(klass, ref_classes)
    col = (klass.name.split('::').last.snakecase + "_id").to_sym

    ids = klass.where(obsoleted_dt: 'infinity').pluck(:group_id)

    ref_ids = ref_classes.map { |rclass|
      rclass.where(obsoleted_dt: 'infinity', col => ids).pluck(col)
    }.flatten.uniq

    klass.where(id: ids - ref_ids).to_a
  end

  # Find Mcfly references from klass instances which have been
  # obsoleted.  A hash is returned with a key for each
  # mcfly_belongs_to reference from klass.
  def self.obsoleted_references(klass)
    assoc_h = Marty::DataConversion.associations(klass)
    assoc_h.each_with_object({}) do
      |(a, ah), h|
      assoc_class = ah[:assoc_class]
      foreign_key = ah[:foreign_key]

      next unless Mcfly.has_mcfly? assoc_class

      h[a] = klass.where(obsoleted_dt: 'infinity').map do
        |obj|
        ref_key = obj.send(foreign_key)
        next unless ref_key
        ref = assoc_class.find(ref_key)
        obj unless Mcfly.is_infinity(ref.obsoleted_dt)
      end.compact
    end
  end
end

Version data entries

123 entries across 123 versions & 1 rubygems

Version Path
marty-2.5.2 lib/marty/relation.rb
marty-2.5.1 lib/marty/relation.rb
marty-2.5.0 lib/marty/relation.rb
marty-2.4.9 lib/marty/relation.rb
marty-2.4.8 lib/marty/relation.rb
marty-2.4.7 lib/marty/relation.rb
marty-2.4.6 lib/marty/relation.rb
marty-2.4.5 lib/marty/relation.rb
marty-2.4.4 lib/marty/relation.rb
marty-2.4.3 lib/marty/relation.rb
marty-2.4.2 lib/marty/relation.rb
marty-2.4.1 lib/marty/relation.rb
marty-2.4.0 lib/marty/relation.rb
marty-2.3.15 lib/marty/relation.rb
marty-2.3.14 lib/marty/relation.rb
marty-2.3.13 lib/marty/relation.rb
marty-2.3.12 lib/marty/relation.rb
marty-2.3.11 lib/marty/relation.rb
marty-2.3.10 lib/marty/relation.rb
marty-2.3.9 lib/marty/relation.rb