Class: Gherkin::Stream::ParserMessageStream

Inherits:
Object
  • Object
show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-gherkin-23.0.1/lib/gherkin/stream/parser_message_stream.rb

Instance Method Summary collapse

Constructor Details

#initialize(paths, sources, options) ⇒ ParserMessageStream

Returns a new instance of ParserMessageStream.



9
10
11
12
13
14
15
16
17
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-gherkin-23.0.1/lib/gherkin/stream/parser_message_stream.rb', line 9

def initialize(paths, sources, options)
  @paths = paths
  @sources = sources
  @options = options

  id_generator = options[:id_generator] || Cucumber::Messages::IdGenerator::UUID.new
  @parser = Parser.new(AstBuilder.new(id_generator))
  @compiler = Pickles::Compiler.new(id_generator)
end

Instance Method Details

#messagesObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-gherkin-23.0.1/lib/gherkin/stream/parser_message_stream.rb', line 19

def messages
  enumerated = false
  Enumerator.new do |y|
    raise DoubleIterationException, "Messages have already been enumerated" if enumerated
    enumerated = true

    sources.each do |source|
      y.yield(Cucumber::Messages::Envelope.new(source: source)) if @options[:include_source]
      begin
        gherkin_document = nil

        if @options[:include_gherkin_document]
          gherkin_document = build_gherkin_document(source)
          y.yield(Cucumber::Messages::Envelope.new(gherkin_document: gherkin_document))
        end
        if @options[:include_pickles]
          gherkin_document ||= build_gherkin_document(source)
          pickles = @compiler.compile(gherkin_document, source)
          pickles.each do |pickle|
            y.yield(Cucumber::Messages::Envelope.new(pickle: pickle))
          end
        end
      rescue CompositeParserException => err
        yield_parse_errors(y, err.errors, source.uri)
      rescue ParserException => err
        yield_parse_errors(y, [err], source.uri)
      end
    end
  end
end