Sha256: 416ab63a296dcc9b3e8d881e9cb1cab9a032488f33cbf65be2a1981b965bc690

Contents?: true

Size: 1.78 KB

Versions: 5

Compression:

Stored size: 1.78 KB

Contents

require_relative './helpers/gherkin_helper'

# == Gherkin Ripper
# does lexing and parsing (building a simple ParseTree for Cucumber Gherkins)
# adding a few support methods to ripping
#
module Cuker

  class GherkinRipper
    include GherkinHelper
    include LoggerSetup

    NoFilesFoundError = Class.new IOError

    attr_accessor :location
    attr_accessor :features
    # attr_reader :ast_map

    def initialize path = '*'
      init_logger

      @location = path.strip
      @location = '.' if @location.empty? # handle blank path searching all features
      @features = get_features @location

      @log.trace "Gherkin ripper running at #{path}"

      @parser = Gherkin::Parser.new
      @ast_map = {}

      @log.info "Parsed '.feature' files @ #{path} = #{@features.size} files"
    end

    def ast_map
      @ast_map = parse_all if @ast_map.empty?
      @ast_map
    end

    private

    # if you need to ignore any pattern of files, change this regex to match those patterns
    IGNORE_EXP = /^$/

    # dir glob for all feature files
    # @param location dir location of all the feature files
    def get_features(path_or_file)
      ext = '.feature'
      files = FileHelper.get_files(path_or_file, ext, IGNORE_EXP)
      files = FileHelper.get_file(path_or_file, ext, IGNORE_EXP) if files.empty?
      raise NoFilesFoundError.new "No '#{ext}' files found @ path '#{path_or_file}'... " if files.empty?
      files
    end

    def parse_all
      parse_hsh = {}
      @features.each do |feat|
        feature_text = File.read(feat)
        scanner = TokenScanner.new(feature_text)
        parse_handle(feat) {
          ast = @parser.parse(scanner)
          parse_hsh[feat] = ast
        }
      end
      parse_hsh
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
cuker-0.5.15 lib/cuker/gherkin_ripper.rb
cuker-0.5.7 lib/cuker/gherkin_ripper.rb
cuker-0.5.3 lib/cuker/gherkin_ripper.rb
cuker-0.4.9 lib/cuker/gherkin_ripper.rb
cuker-0.4.5 lib/cuker/gherkin_ripper.rb