Class: Chef::VersionConstraint

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/version_constraint.rb,
lib/chef/version_constraint/platform.rb

Direct Known Subclasses

Platform

Defined Under Namespace

Classes: Platform

Constant Summary collapse

DEFAULT_CONSTRAINT =
">= 0.0.0".freeze
STANDARD_OPS =
%w{< > <= >=}.freeze
OPS =
%w{< > = <= >= ~>}.freeze
PATTERN =
/^(#{OPS.join('|')}) *([0-9].*)$/.freeze
VERSION_CLASS =
Chef::Version

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(constraint_spec = DEFAULT_CONSTRAINT) ⇒ VersionConstraint

Returns a new instance of VersionConstraint


29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/chef/version_constraint.rb', line 29

def initialize(constraint_spec = DEFAULT_CONSTRAINT)
  case constraint_spec
  when nil
    parse(DEFAULT_CONSTRAINT)
  when Array
    parse_from_array(constraint_spec)
  when String
    parse(constraint_spec)
  else
    msg = "VersionConstraint should be created from a String. You gave: #{constraint_spec.inspect}"
    raise Chef::Exceptions::InvalidVersionConstraint, msg
  end
end

Instance Attribute Details

#opObject (readonly)

Returns the value of attribute op


27
28
29
# File 'lib/chef/version_constraint.rb', line 27

def op
  @op
end

#versionObject (readonly)

Returns the value of attribute version


27
28
29
# File 'lib/chef/version_constraint.rb', line 27

def version
  @version
end

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)

60
61
62
# File 'lib/chef/version_constraint.rb', line 60

def eql?(other)
  other.class == self.class && @op == other.op && @version == other.version
end

#include?(v) ⇒ Boolean

Returns:

  • (Boolean)

43
44
45
46
47
48
49
50
# File 'lib/chef/version_constraint.rb', line 43

def include?(v)
  version = if v.respond_to? :version # a CookbookVersion-like object
              self.class::VERSION_CLASS.new(v.version.to_s)
            else
              self.class::VERSION_CLASS.new(v.to_s)
            end
  do_op(version)
end

#inspectObject


52
53
54
# File 'lib/chef/version_constraint.rb', line 52

def inspect
  "(#{self})"
end

#to_sObject


56
57
58
# File 'lib/chef/version_constraint.rb', line 56

def to_s
  "#{@op} #{@raw_version}"
end