Sha256: 11a3e2eb8fa5f1e0bb09d673c982701cef7abf84d63be28a12a5883277f65d60

Contents?: true

Size: 1.7 KB

Versions: 11

Compression:

Stored size: 1.7 KB

Contents

module DataMapper
  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 DataMapper

Version data entries

11 entries across 11 versions & 4 rubygems

Version Path
sbf-dm-core-1.5.0 lib/dm-core/support/descendant_set.rb
sbf-dm-core-1.4.0 lib/dm-core/support/descendant_set.rb
sbf-dm-core-1.3.0 lib/dm-core/support/descendant_set.rb
sbf-dm-core-1.3.0.beta lib/dm-core/support/descendant_set.rb
ardm-core-1.3.0 lib/dm-core/support/descendant_set.rb
ardm-core-1.2.1 lib/dm-core/support/descendant_set.rb
dm-core-1.2.1 lib/dm-core/support/descendant_set.rb
ghost_dm-core-1.3.0.beta lib/dm-core/support/descendant_set.rb
dm-core-1.2.0 lib/dm-core/support/descendant_set.rb
dm-core-1.2.0.rc2 lib/dm-core/support/descendant_set.rb
dm-core-1.2.0.rc1 lib/dm-core/support/descendant_set.rb