Class: Bundler::GemVersionPromoter
- Inherits:
-
Object
- Object
- Bundler::GemVersionPromoter
- Defined in:
- lib/bundler/gem_version_promoter.rb
Overview
This class contains all of the logic for determining the next version of a Gem to update to based on the requested level (patch, minor, major). Primarily designed to work with Resolver which will provide it the list of available dependency versions as found in its index, before returning it to to the resolution engine to select the best version.
Instance Attribute Summary collapse
-
#level ⇒ Object
Returns the value of attribute level.
-
#pre ⇒ Object
Returns the value of attribute pre.
-
#strict ⇒ Object
By default, strict is false, meaning every available version of a gem is returned from sort_versions.
Instance Method Summary collapse
-
#initialize ⇒ GemVersionPromoter
constructor
Creates a GemVersionPromoter instance.
-
#major? ⇒ bool
Convenience method for testing value of level variable.
-
#minor? ⇒ bool
Convenience method for testing value of level variable.
-
#pre? ⇒ bool
Convenience method for testing value of pre variable.
-
#sort_versions(package, specs) ⇒ Specification
Given a Resolver::Package and an Array of Specifications of available versions for a gem, this method will return the Array of Specifications sorted (and possibly truncated if strict is true) in an order to give preference to the current level (:major, :minor or :patch) when resolution is deciding what versions best resolve all dependencies in the bundle.
Constructor Details
#initialize ⇒ GemVersionPromoter
Creates a GemVersionPromoter instance.
29 30 31 32 33 |
# File 'lib/bundler/gem_version_promoter.rb', line 29 def initialize @level = :major @strict = false @pre = false end |
Instance Attribute Details
#level ⇒ Object
Returns the value of attribute level.
10 11 12 |
# File 'lib/bundler/gem_version_promoter.rb', line 10 def level @level end |
#pre ⇒ Object
Returns the value of attribute pre.
11 12 13 |
# File 'lib/bundler/gem_version_promoter.rb', line 11 def pre @pre end |
#strict ⇒ Object
By default, strict is false, meaning every available version of a gem is returned from sort_versions. The order gives preference to the requested level (:patch, :minor, :major) but in complicated requirement cases some gems will by necessity be promoted past the requested level, or even reverted to older versions.
If strict is set to true, the results from sort_versions will be truncated, eliminating any version outside the current level scope. This can lead to unexpected outcomes or even VersionConflict exceptions that report a version of a gem not existing for versions that indeed do existing in the referenced source.
24 25 26 |
# File 'lib/bundler/gem_version_promoter.rb', line 24 def strict @strict end |
Instance Method Details
#major? ⇒ bool
Returns Convenience method for testing value of level variable.
62 63 64 |
# File 'lib/bundler/gem_version_promoter.rb', line 62 def major? level == :major end |
#minor? ⇒ bool
Returns Convenience method for testing value of level variable.
67 68 69 |
# File 'lib/bundler/gem_version_promoter.rb', line 67 def minor? level == :minor end |
#pre? ⇒ bool
Returns Convenience method for testing value of pre variable.
72 73 74 |
# File 'lib/bundler/gem_version_promoter.rb', line 72 def pre? pre == true end |
#sort_versions(package, specs) ⇒ Specification
Given a Resolver::Package and an Array of Specifications of available versions for a gem, this method will return the Array of Specifications sorted (and possibly truncated if strict is true) in an order to give preference to the current level (:major, :minor or :patch) when resolution is deciding what versions best resolve all dependencies in the bundle.
55 56 57 58 59 |
# File 'lib/bundler/gem_version_promoter.rb', line 55 def sort_versions(package, specs) specs = filter_dep_specs(specs, package) if strict sort_dep_specs(specs, package) end |