Sha256: 4c2bf2bcad98c6cea656582155e0b49be95687e90f9720bd8bb6823991bd8575

Contents?: true

Size: 1.69 KB

Versions: 24

Compression:

Stored size: 1.69 KB

Contents

module Gherkin
  class Query
    def initialize
      @ast_node_locations = {}
    end

    def update(message)
      update_feature(message.gherkin_document.feature) if message.gherkin_document
    end

    def location(ast_node_id)
      return @ast_node_locations[ast_node_id] if @ast_node_locations.has_key?(ast_node_id)
      raise AstNodeNotLocatedException, "No location found for #{ast_node_id} }. Known: #{@ast_node_locations.keys}"
    end

    private

    def update_feature(feature)
      return if feature.nil?
      store_nodes_location(feature.tags)

      feature.children.each do |child|
        update_rule(child.rule) if child.rule
        update_background(child.background) if child.background
        update_scenario(child.scenario) if child.scenario
      end
    end

    def update_rule(rule)
      return if rule.nil?
      store_nodes_location(rule.tags)

      rule.children.each do |child|
        update_background(child.background) if child.background
        update_scenario(child.scenario) if child.scenario
      end
    end

    def update_background(background)
      update_steps(background.steps)
    end

    def update_scenario(scenario)
      store_node_location(scenario)
      store_nodes_location(scenario.tags)
      update_steps(scenario.steps)
      scenario.examples.each do |examples|
        store_nodes_location(examples.tags || [])
        store_nodes_location(examples.table_body || [])
      end
    end

    def update_steps(steps)
      store_nodes_location(steps)
    end

    def store_nodes_location(nodes)
      nodes.each { |node| store_node_location(node) }
    end

    def store_node_location(node)
      @ast_node_locations[node.id] = node.location
    end
  end
end

Version data entries

24 entries across 24 versions & 4 rubygems

Version Path
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/cucumber-gherkin-26.2.0/lib/gherkin/query.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/cucumber-gherkin-26.2.0/lib/gherkin/query.rb
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-gherkin-23.0.1/lib/gherkin/query.rb
cucumber-gherkin-26.2.0 lib/gherkin/query.rb
cucumber-gherkin-26.1.0 lib/gherkin/query.rb
rubypitaya-3.12.4 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-gherkin-23.0.1/lib/gherkin/query.rb
rubypitaya-3.12.3 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-gherkin-23.0.1/lib/gherkin/query.rb
rubypitaya-3.12.2 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-gherkin-23.0.1/lib/gherkin/query.rb
cucumber-gherkin-26.0.3 lib/gherkin/query.rb
cucumber-gherkin-26.0.2 lib/gherkin/query.rb
cucumber-gherkin-26.0.1 lib/gherkin/query.rb
cucumber-gherkin-26.0.0 lib/gherkin/query.rb
cucumber-gherkin-25.0.2 lib/gherkin/query.rb
cucumber-gherkin-25.0.1 lib/gherkin/query.rb
cucumber-gherkin-25.0.0 lib/gherkin/query.rb
cucumber-gherkin-24.1.0 lib/gherkin/query.rb
cucumber-gherkin-24.0.0 lib/gherkin/query.rb
cucumber-gherkin-23.0.1 lib/gherkin/query.rb
cucumber-gherkin-23.0.0 lib/gherkin/query.rb
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/cucumber-gherkin-22.0.0/lib/gherkin/query.rb