Class: GemBench::StrictVersionGem

Inherits:
Object
  • Object
show all
Defined in:
lib/gem_bench/strict_version_gem.rb

Overview

Helps determine if a gem dependency is “valid” according to the strict rules of:

- every gem must have a version requirement of some sort

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, version, version_type, valid, relevant_lines, index, tokenized_line = nil) ⇒ StrictVersionGem

Returns a new instance of StrictVersionGem.



24
25
26
27
28
29
30
31
32
# File 'lib/gem_bench/strict_version_gem.rb', line 24

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

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



5
6
7
# File 'lib/gem_bench/strict_version_gem.rb', line 5

def index
  @index
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/gem_bench/strict_version_gem.rb', line 5

def name
  @name
end

#relevant_linesObject (readonly)

Returns the value of attribute relevant_lines.



5
6
7
# File 'lib/gem_bench/strict_version_gem.rb', line 5

def relevant_lines
  @relevant_lines
end

#tokenized_lineObject (readonly)

Returns the value of attribute tokenized_line.



5
6
7
# File 'lib/gem_bench/strict_version_gem.rb', line 5

def tokenized_line
  @tokenized_line
end

#validObject (readonly)

Returns the value of attribute valid.



5
6
7
# File 'lib/gem_bench/strict_version_gem.rb', line 5

def valid
  @valid
end

#versionObject (readonly)

Returns the value of attribute version.



5
6
7
# File 'lib/gem_bench/strict_version_gem.rb', line 5

def version
  @version
end

#version_typeObject (readonly)

Returns the value of attribute version_type.



5
6
7
# File 'lib/gem_bench/strict_version_gem.rb', line 5

def version_type
  @version_type
end

Class Method Details

.from_line(all_lines, line, index, opts = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/gem_bench/strict_version_gem.rb', line 8

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

Instance Method Details

#is_type?(type) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/gem_bench/strict_version_gem.rb', line 38

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

#to_sObject



42
43
44
45
46
47
48
49
50
# File 'lib/gem_bench/strict_version_gem.rb', line 42

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

#valid?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/gem_bench/strict_version_gem.rb', line 34

def valid?
  valid
end