Sha256: de058f767d87064009a1002b1e0be624b4fcfe67a7b58bb80a40e7bd20ff3d51

Contents?: true

Size: 1.43 KB

Versions: 2

Compression:

Stored size: 1.43 KB

Contents

module GemBench
  # Helps determine if a gem dependency is "valid" according to the strict rules of:
  #   - every gem must have a version requirement of some sort
  class StrictVersionGem
    attr_reader :name, :version, :version_type, :valid, :relevant_lines, :index, :tokenized_line

    class << self
      def from_line(all_lines, line, index, opts = {})
        tokenized_line = GemfileLineTokenizer.new(all_lines, line, index)
        return unless tokenized_line.parse_success

        new(
          tokenized_line.name,
          tokenized_line.version,
          tokenized_line.version_type,
          tokenized_line.valid,
          tokenized_line.relevant_lines,
          tokenized_line.index,
          (opts[:debug] == true) ? tokenized_line : nil,
        )
      end
    end

    def initialize(name, version, version_type, valid, relevant_lines, index, tokenized_line = nil)
      @name = name
      @version = version
      @version_type = version_type ? version_type.to_sym : :unknown
      @valid = valid
      @relevant_lines = relevant_lines
      @index = index
      @tokenized_line = tokenized_line # for debugging
    end

    def valid?
      valid
    end

    def is_type?(type)
      version_type == type.to_sym
    end

    def to_s
      <<~EOS
        Gem: #{name}
        Line Number: #{index}
        Version: #{version.inspect}
        Relevant Gemfile Lines:
        #{relevant_lines.join("\n")}
      EOS
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gem_bench-2.0.5 lib/gem_bench/strict_version_gem.rb
gem_bench-2.0.4 lib/gem_bench/strict_version_gem.rb