Class: DepSelector::VersionConstraint

Inherits:
Object
  • Object
show all
Defined in:
lib/dep_selector/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 = nil) ⇒ VersionConstraint

Returns a new instance of VersionConstraint.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/dep_selector/version_constraint.rb', line 31

def initialize(constraint_spec=nil)
  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 Exceptions::InvalidVersionConstraint, msg
  end
end

Instance Attribute Details

#opObject (readonly)

Returns the value of attribute op.



29
30
31
# File 'lib/dep_selector/version_constraint.rb', line 29

def op
  @op
end

#versionObject (readonly)

Returns the value of attribute version.



29
30
31
# File 'lib/dep_selector/version_constraint.rb', line 29

def version
  @version
end

Instance Method Details

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

Returns:

  • (Boolean)


66
67
68
# File 'lib/dep_selector/version_constraint.rb', line 66

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

#include?(v) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
49
50
51
52
53
54
55
56
# File 'lib/dep_selector/version_constraint.rb', line 46

def include?(v)
  version = if v.kind_of?(Version)
              v
            elsif
              v.respond_to? :version
              Version.new(v.version.to_s)
            else
              Version.new(v.to_s)
            end
 do_op(version)
end

#inspectObject



58
59
60
# File 'lib/dep_selector/version_constraint.rb', line 58

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

#to_sObject



62
63
64
# File 'lib/dep_selector/version_constraint.rb', line 62

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