class Parcels::DependencyParcelList

Attributes

loose_parcels[R]
parcel_to_tag_map[R]
tag_to_child_tag_map[R]
tag_to_parcel_map[R]

Public Class Methods

new() click to toggle source
# File lib/parcels/dependency_parcel_list.rb, line 5
def initialize
  @tag_to_child_tag_map = { }
  @parcel_to_tag_map = { }
  @tag_to_parcel_map = { }

  @loose_parcels = [ ]
end

Public Instance Methods

add_parcels!(parcels) click to toggle source
# File lib/parcels/dependency_parcel_list.rb, line 25
def add_parcels!(parcels)
  parcels.each do |parcel|
    if parcel.tag
      parcel_to_tag_map[parcel] = parcel.tag
      tag_to_parcel_map[parcel.tag] = parcel

      parcel.tags_that_must_come_before.each do |tag_that_must_come_before|
        tag_to_child_tag_map[tag_that_must_come_before] ||= [ ]
        tag_to_child_tag_map[tag_that_must_come_before] << parcel.tag
      end
    else
      loose_parcels << parcel
    end
  end
end
parcels_in_order() click to toggle source
# File lib/parcels/dependency_parcel_list.rb, line 41
def parcels_in_order
  tsort.reverse # tsort puts children before parents; we want the exact opposite
end
tsort_each_child(parcel, &block) click to toggle source
# File lib/parcels/dependency_parcel_list.rb, line 17
def tsort_each_child(parcel, &block)
  tag = parcel_to_tag_map[parcel]
  child_tags = tag_to_child_tag_map[tag] || [ ]
  child_parcels = child_tags.map { |t| tag_to_parcel_map[t] }.compact

  child_parcels.each(&block)
end
tsort_each_node(&block) click to toggle source
# File lib/parcels/dependency_parcel_list.rb, line 13
def tsort_each_node(&block)
  parcel_to_tag_map.keys.each(&block)
end