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.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/gem_bench/strict_version_requirement.rb', line 9

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 self.verbose
end

Instance Attribute Details

#benchersObject (readonly)

Returns the value of attribute benchers.



6
7
8
# File 'lib/gem_bench/strict_version_requirement.rb', line 6

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.



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

def gems
  @gems
end

#startersObject (readonly)

Returns the value of attribute starters.



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

def starters
  @starters
end

#verboseObject (readonly)

Returns the value of attribute verbose.



7
8
9
# File 'lib/gem_bench/strict_version_requirement.rb', line 7

def verbose
  @verbose
end

Instance Method Details

#find(name) ⇒ Object



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

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

#gem_at(index) ⇒ Object



39
40
41
# File 'lib/gem_bench/strict_version_requirement.rb', line 39

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

#list_missing_version_constraintsObject



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

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


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/gem_bench/strict_version_requirement.rb', line 43

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)


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

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