Class: Richcss::VersionKit::Requirement
- Inherits:
-
Object
- Object
- Richcss::VersionKit::Requirement
- Defined in:
- lib/richcss/vendor/version_kit/lib/version_kit/requirement.rb
Overview
Describes a constraint on the acceptable elements of a list of versions. The only relevant method for this class is the #satisfied_by? method.
The optimistic requirement is deemed optimistic because the user if optimistic about the correct versioning of the software the requirement refers to.
Constant Summary collapse
- OPERATORS =
Returns The operators supported by this class associated to the lambda used to evaluate them.
['=', '!=', '>', '<', '>=', '<=', '~>']
Instance Attribute Summary collapse
-
#operator ⇒ String
readonly
The operator of the constraint.
-
#reference_version ⇒ String
readonly
The reference version of the operator.
Object methods collapse
-
#<=>(other) ⇒ Fixnum
Useful for sorting a list of requirements.
- #==(other) ⇒ Object
-
#hash ⇒ Fixnum
The hash of the instance.
-
#to_s ⇒ String
The string representation of this class.
Instance Method Summary collapse
-
#initialize(string) ⇒ Requirement
constructor
A new instance of Requirement.
-
#satisfied_by?(candidate_version) ⇒ Bool
rubocop:disable MethodLength, CyclomaticComplexity.
Constructor Details
#initialize(string) ⇒ Requirement
Returns a new instance of Requirement.
25 26 27 28 29 30 31 32 |
# File 'lib/richcss/vendor/version_kit/lib/version_kit/requirement.rb', line 25 def initialize(string) operator, reference_version = parse_string(string) check_parsing(string, operator, reference_version) @operator = operator @reference_version = reference_version @reference = Version.new(reference_version) end |
Instance Attribute Details
#operator ⇒ String (readonly)
Returns The operator of the constraint.
12 13 14 |
# File 'lib/richcss/vendor/version_kit/lib/version_kit/requirement.rb', line 12 def operator @operator end |
#reference_version ⇒ String (readonly)
Returns The reference version of the operator.
16 17 18 |
# File 'lib/richcss/vendor/version_kit/lib/version_kit/requirement.rb', line 16 def reference_version @reference_version end |
Instance Method Details
#<=>(other) ⇒ Fixnum
Returns Useful for sorting a list of requirements.
74 75 76 |
# File 'lib/richcss/vendor/version_kit/lib/version_kit/requirement.rb', line 74 def <=>(other) to_s <=> other.to_s end |
#==(other) ⇒ Object
84 85 86 87 |
# File 'lib/richcss/vendor/version_kit/lib/version_kit/requirement.rb', line 84 def ==(other) operator == other.operator && reference_version == other.reference_version end |
#hash ⇒ Fixnum
Returns The hash of the instance.
80 81 82 |
# File 'lib/richcss/vendor/version_kit/lib/version_kit/requirement.rb', line 80 def hash to_s.hash end |
#satisfied_by?(candidate_version) ⇒ Bool
rubocop:disable MethodLength, CyclomaticComplexity
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/richcss/vendor/version_kit/lib/version_kit/requirement.rb', line 41 def satisfied_by?(candidate_version) candidate = Version.new(candidate_version) reference = @reference case operator when '=' then candidate == reference when '!=' then candidate != reference when '>' then candidate > reference when '<' then candidate < reference when '>=' then candidate >= reference when '<=' then candidate <= reference when '~>' candidate >= reference && candidate < bumped_reference_version end end |
#to_s ⇒ String
Returns the string representation of this class. The string is equivalent, but not strictly equal, to the one used on initialization.
68 69 70 |
# File 'lib/richcss/vendor/version_kit/lib/version_kit/requirement.rb', line 68 def to_s "#{operator} #{reference_version}" end |