module Saxerator
  class DocumentFragment
    include Enumerable
    include DSL

    def initialize(source, config = nil, latches = [])
      @source = source
      @latches = latches
      @config = config
    end

    def each(&block)
      # Always have to start at the beginning of a File
      @source.rewind if @source.respond_to?(:rewind)

      reader = Parser::LatchedAccumulator.new(@config, @latches, block)
      @config.adapter.parse(@source, reader)
    end
  end
end

module Saxerator
  class DocumentFragment
    include Enumerable
    include DSL

    def initialize(source, config = nil, latches = [])
      @source = source
      @latches = latches
      @config = config
    end

    def each(&block)
      return to_enum unless block_given?

      # Always have to start at the beginning of a File
      @source.rewind if @source.respond_to?(:rewind)

      reader = Parser::LatchedAccumulator.new(@config, @latches, block)
      @config.adapter.parse(@source, reader)
    end
  end
end

Return an enumerator if no block is given
Return an enumerator if no block is given

This is the typical pattern for Enumerable objects, and was an oversight
that it was not already-included here.

See http://ruby-doc.org/core-2.4.1/Object.html#method-i-to_enum
