Sha256: af596978e60546d551053f945a1a5e2dc31e6fe45849c7ccbf8201acf3c1cdf1

Contents?: true

Size: 1.69 KB

Versions: 15

Compression:

Stored size: 1.69 KB

Contents

module Ardm
  class DescendantSet
    include Enumerable

    # Initialize a DescendantSet instance
    #
    # @param [#to_ary] descendants
    #   initialize with the descendants
    #
    # @api private
    def initialize(descendants = [])
      @descendants = SubjectSet.new(descendants)
    end

    # Copy a DescendantSet instance
    #
    # @param [DescendantSet] original
    #   the original descendants
    #
    # @api private
    def initialize_copy(original)
      @descendants = @descendants.dup
    end

    # Add a descendant
    #
    # @param [Module] descendant
    #
    # @return [DescendantSet]
    #   self
    #
    # @api private
    def <<(descendant)
      @descendants << descendant
      self
    end

    # Remove a descendant
    #
    # Also removes from all descendants
    #
    # @param [Module] descendant
    #
    # @return [DescendantSet]
    #   self
    #
    # @api private
    def delete(descendant)
      @descendants.delete(descendant)
      each { |d| d.descendants.delete(descendant) }
    end

    # Iterate over each descendant
    #
    # @yield [descendant]
    # @yieldparam [Module] descendant
    #
    # @return [DescendantSet]
    #   self
    #
    # @api private
    def each
      @descendants.each do |descendant|
        yield descendant
        descendant.descendants.each { |dd| yield dd }
      end
      self
    end

    # Test if there are any descendants
    #
    # @return [Boolean]
    #
    # @api private
    def empty?
      @descendants.empty?
    end

    # Removes all entries and returns self
    #
    # @return [DescendantSet] self
    #
    # @api private
    def clear
      @descendants.clear
    end

  end # class DescendantSet
end # module Ardm

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
ardm-0.4.0.ar427 lib/ardm/support/descendant_set.rb
ardm-0.4.0 lib/ardm/support/descendant_set.rb
ardm-0.3.2 lib/ardm/support/descendant_set.rb
ardm-0.3.1 lib/ardm/support/descendant_set.rb
ardm-0.3.0 lib/ardm/support/descendant_set.rb
ardm-0.2.7 lib/ardm/support/descendant_set.rb
ardm-0.2.6 lib/ardm/support/descendant_set.rb
ardm-0.2.5 lib/ardm/support/descendant_set.rb
ardm-0.2.4 lib/ardm/support/descendant_set.rb
ardm-0.2.3 lib/ardm/support/descendant_set.rb
ardm-0.2.2 lib/ardm/support/descendant_set.rb
ardm-0.2.1 lib/ardm/support/descendant_set.rb
ardm-0.2.0 lib/ardm/support/descendant_set.rb
ardm-0.1.0 lib/ardm/support/descendant_set.rb
ardm-0.0.1 lib/ardm/support/descendant_set.rb