class Chef::Sugar::Constraints::Version
This class exposes a single version constraint object that wraps the string representation of a version string and proved helpful comparator methods.
@example Create a new version
Chef::Sugar::Version('1.2.3')
@example Compare a version with constraints
Chef::Sugar::Version('1.2.3').satisfies?('~> 1.3.4', '< 2.0.5')
Public Class Methods
new(version)
click to toggle source
Create a new version object.
@param [String] version
the version to create
Calls superclass method
# File lib/chef/sugar/constraints.rb, line 81 def initialize(version) super @version = Gem::Version.new(version) end
Public Instance Methods
satisfies?(*constraints)
click to toggle source
Determine if the given constraint is satisfied by this version.
@example Given a satisified version
Version.new('1.2.5').satisfies?('~> 1.2.0') #=> true
@example Given an unsatisfied version
Version.new('2.0.0').satisfies?('~> 1.2.0') #=> false
@param [String, Array
<String>] constraints
the constraints to satisfy
@return [Boolean]
true if the version satisfies the constraints, false otherwise
# File lib/chef/sugar/constraints.rb, line 102 def satisfies?(*constraints) Gem::Requirement.new(*constraints).satisfied_by?(@version) end