Class: GemBench::StrictVersionRequirement
- Inherits:
-
Object
- Object
- GemBench::StrictVersionRequirement
- Defined in:
- lib/gem_bench/strict_version_requirement.rb
Overview
Helps enforce a version requirement for every dependency in a Gemfile
Instance Attribute Summary collapse
-
#benchers ⇒ Object
readonly
Returns the value of attribute benchers.
-
#gemfile_path ⇒ Object
readonly
Returns the value of attribute gemfile_path.
-
#gems ⇒ Object
readonly
Returns the value of attribute gems.
-
#starters ⇒ Object
readonly
Returns the value of attribute starters.
-
#verbose ⇒ Object
readonly
Returns the value of attribute verbose.
Instance Method Summary collapse
- #find(name) ⇒ Object
- #gem_at(index) ⇒ Object
-
#initialize(options = {}) ⇒ StrictVersionRequirement
constructor
A new instance of StrictVersionRequirement.
- #list_missing_version_constraints ⇒ Object
- #print ⇒ Object
- #versions_present? ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ StrictVersionRequirement
Returns a new instance of StrictVersionRequirement.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/gem_bench/strict_version_requirement.rb', line 6 def initialize( = {}) @gemfile_path = .fetch(: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 = [:verbose] self.print if verbose end |
Instance Attribute Details
#benchers ⇒ Object (readonly)
Returns the value of attribute benchers.
4 5 6 |
# File 'lib/gem_bench/strict_version_requirement.rb', line 4 def benchers @benchers end |
#gemfile_path ⇒ Object (readonly)
Returns the value of attribute gemfile_path.
4 5 6 |
# File 'lib/gem_bench/strict_version_requirement.rb', line 4 def gemfile_path @gemfile_path end |
#gems ⇒ Object (readonly)
Returns the value of attribute gems.
4 5 6 |
# File 'lib/gem_bench/strict_version_requirement.rb', line 4 def gems @gems end |
#starters ⇒ Object (readonly)
Returns the value of attribute starters.
4 5 6 |
# File 'lib/gem_bench/strict_version_requirement.rb', line 4 def starters @starters end |
#verbose ⇒ Object (readonly)
Returns the value of attribute verbose.
4 5 6 |
# File 'lib/gem_bench/strict_version_requirement.rb', line 4 def verbose @verbose end |
Instance Method Details
#find(name) ⇒ Object
32 33 34 |
# File 'lib/gem_bench/strict_version_requirement.rb', line 32 def find(name) gems.detect { |x| x.name == name } end |
#gem_at(index) ⇒ Object
36 37 38 |
# File 'lib/gem_bench/strict_version_requirement.rb', line 36 def gem_at(index) gems.detect { |x| x.index == index } end |
#list_missing_version_constraints ⇒ Object
28 29 30 |
# File 'lib/gem_bench/strict_version_requirement.rb', line 28 def list_missing_version_constraints benchers.map { |x| x.name } end |
#print ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/gem_bench/strict_version_requirement.rb', line 40 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
24 25 26 |
# File 'lib/gem_bench/strict_version_requirement.rb', line 24 def versions_present? gems.detect { |x| !x.valid? }.nil? end |