Class: GemBench::StrictVersionRequirement

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ StrictVersionRequirement

Returns a new instance of StrictVersionRequirement.



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

def initialize(options = {})
  @gemfile_path = "#{Dir.pwd}/Gemfile"
  file = File.open(gemfile_path)
  # Get all lines as an array
  all_lines = file.readlines
  @gems = []
  all_lines.each_with_index do |line, index|
    # will return nil if the line is not a gem line
    gem = StrictVersionGem.from_line(all_lines, line, index)
    @gems << gem if gem
  end

  @starters, @benchers = @gems.partition { |x| x.valid? }
  # Remove all the commented || blank lines
  @verbose = options[:verbose]
  self.print if verbose
end

Instance Attribute Details

#benchersObject (readonly)

Returns the value of attribute benchers.



3
4
5
# File 'lib/gem_bench/strict_version_requirement.rb', line 3

def benchers
  @benchers
end

#gemfile_pathObject (readonly)

Returns the value of attribute gemfile_path.



3
4
5
# File 'lib/gem_bench/strict_version_requirement.rb', line 3

def gemfile_path
  @gemfile_path
end

#gemsObject (readonly)

Returns the value of attribute gems.



3
4
5
# File 'lib/gem_bench/strict_version_requirement.rb', line 3

def gems
  @gems
end

#startersObject (readonly)

Returns the value of attribute starters.



3
4
5
# File 'lib/gem_bench/strict_version_requirement.rb', line 3

def starters
  @starters
end

#verboseObject (readonly)

Returns the value of attribute verbose.



3
4
5
# File 'lib/gem_bench/strict_version_requirement.rb', line 3

def verbose
  @verbose
end

Instance Method Details

#find(name) ⇒ Object



31
32
33
# File 'lib/gem_bench/strict_version_requirement.rb', line 31

def find(name)
  gems.detect { |x| x.name == name }
end

#gem_at(index) ⇒ Object



35
36
37
# File 'lib/gem_bench/strict_version_requirement.rb', line 35

def gem_at(index)
  gems.detect { |x| x.index == index }
end

#list_missing_version_constraintsObject



27
28
29
# File 'lib/gem_bench/strict_version_requirement.rb', line 27

def list_missing_version_constraints
  benchers.map { |x| x.name }
end


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/gem_bench/strict_version_requirement.rb', line 39

def print
  using_path = benchers.count { |x| x.is_type?(:path) }
  puts <<~EOS
    #{"      "}
    The gems that need to be improved are:

    #{benchers.map(&:to_s).join("\n")}

    There are #{starters.length} gems that have valid strict version constraints.
    Of those:
      #{starters.count { |x| x.is_type?(:constraint) }} use primary constraints (e.g. '~> 1.2.3').
      #{starters.count { |x| x.is_type?(:git_ref) }} use git ref constraints.
      #{starters.count { |x| x.is_type?(:git_tag) }} use git tag constraints.

    There are #{benchers.length} gems that do not have strict version constraints.
    Of those:
      #{benchers.count { |x| x.is_type?(:git_branch) }} use git branch constraints.
      #{benchers.count { |x| x.is_type?(:git) }} use some other form of git constraint considered not strict enough.
      #{benchers.count { |x| x.is_type?(:unknown) }} gems seem to not have any constraint at all.
      #{using_path} gems are using a local path. #{"WARNING!!!" if using_path > 0}
  EOS
end

#versions_present?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/gem_bench/strict_version_requirement.rb', line 23

def versions_present?
  gems.detect { |x| !x.valid? }.nil?
end