Class: Chef::VersionConstraint

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

Constant Summary collapse

DEFAULT_CONSTRAINT =
">= 0.0.0"
STANDARD_OPS =
%w(< > <= >=)
OPS =
%w(< > = <= >= ~>)
PATTERN =
/^(#{OPS.join('|')}) (.+)$/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(constraint_spec = DEFAULT_CONSTRAINT) ⇒ VersionConstraint

Returns a new instance of VersionConstraint.



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

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.



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

def op
  @op
end

#versionObject (readonly)

Returns the value of attribute version.



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

def version
  @version
end

Instance Method Details

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

Returns:

  • (Boolean)


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

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

#include?(v) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#inspectObject



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

def inspect
  "(#{@op} #{@version})"
end

#to_sObject



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

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