lib/chef/sugar/constraints.rb in chef-sugar-3.2.0 vs lib/chef/sugar/constraints.rb in chef-sugar-3.3.0
- old
+ new
@@ -15,39 +15,11 @@
#
class Chef
module Sugar
module Constraints
- extend self
-
#
- # Shortcut method for creating a new {Version} object.
- #
- # @param [String] version
- # the version (as a string) to create
- #
- # @return [Chef::Sugar::Constraints::Version]
- # the new version object
- #
- def version(version)
- Chef::Sugar::Constraints::Version.new(version)
- end
-
- #
- # Shortcut method for creating a new {Constraint} object.
- #
- # @param [String, Array<String>] constraints
- # the list of constraints to use
- #
- # @return [Chef::Sugar::Constraints::Constraint]
- # the new constraint object
- #
- def constraint(*constraints)
- Chef::Sugar::Constraints::Constraint.new(*constraints)
- end
-
- #
# This class is a wrapper around a version requirement that adds a nice
# DSL for comparing constraints:
#
# @example Comparing a single constraint
# Constraint.new('~> 1.2.3').satisfied_by?('1.2.7')
@@ -97,18 +69,19 @@
# 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')
#
- class Version
+ class Version < String
#
# Create a new version object.
#
# @param [String] version
# the version to create
#
def initialize(version)
+ super
@version = Gem::Version.new(version)
end
#
# Determine if the given constraint is satisfied by this version.
@@ -127,35 +100,9 @@
# true if the version satisfies the constraints, false otherwise
#
def satisfies?(*constraints)
Gem::Requirement.new(*constraints).satisfied_by?(@version)
end
- end
- end
-
- module DSL
- # @see Chef::Sugar::Constraints#version
- def version(version)
- Chef::Sugar::Constraints::Version.new(version)
- end
-
- # @see Chef::Sugar::Constraints#constraint
- def constraint(*constraints)
- Chef::Sugar::Constraints.constraint(*constraints)
- end
-
- #
- # This wrapper/convenience method is only available in the recipe DSL. It
- # creates a new version object from the {Chef::VERSION}.
- #
- # @example Check if Chef 11+
- # chef_version.satisfies?('>= 11.0.0')
- #
- # @return [Chef::Sugar::Constraints::Version]
- # a version object, wrapping the current {Chef::VERSION}
- #
- def chef_version
- version(Chef::VERSION)
end
end
end
end