Class: Git::VersionConstraint
- Inherits:
-
Data
- Object
- Data
- Git::VersionConstraint
- Defined in:
- lib/git/version_constraint.rb
Overview
Represents a git version constraint with minimum and upper bound versions
Used by Commands::Base.requires_git_version to declare version requirements and by VersionError to report constraint violations.
Instance Attribute Summary collapse
-
#before ⇒ Object
readonly
Returns the value of attribute before.
-
#min ⇒ Object
readonly
Returns the value of attribute min.
Instance Method Summary collapse
-
#initialize(min: nil, before: nil) ⇒ VersionConstraint
constructor
Initialize a new VersionConstraint.
-
#satisfied_by?(version) ⇒ Boolean
Check if the given version satisfies this constraint.
-
#to_s ⇒ String
Return a human-readable representation of this constraint.
-
#too_new?(version) ⇒ Boolean
Check if the given version is too new (at or past the upper bound).
-
#too_old?(version) ⇒ Boolean
Check if the given version is too old (below the minimum).
Constructor Details
#initialize(min: nil, before: nil) ⇒ VersionConstraint
Initialize a new VersionConstraint
35 36 37 |
# File 'lib/git/version_constraint.rb', line 35 def initialize(min: nil, before: nil) super end |
Instance Attribute Details
#before ⇒ Object (readonly)
Returns the value of attribute before
28 29 30 |
# File 'lib/git/version_constraint.rb', line 28 def before @before end |
#min ⇒ Object (readonly)
Returns the value of attribute min
28 29 30 |
# File 'lib/git/version_constraint.rb', line 28 def min @min end |
Instance Method Details
#satisfied_by?(version) ⇒ Boolean
Check if the given version satisfies this constraint
69 70 71 |
# File 'lib/git/version_constraint.rb', line 69 def satisfied_by?(version) !too_old?(version) && !too_new?(version) end |
#to_s ⇒ String
Return a human-readable representation of this constraint
77 78 79 80 81 82 83 |
# File 'lib/git/version_constraint.rb', line 77 def to_s return ">= #{min}, < #{before}" if min && before return ">= #{min}" if min return "< #{before}" if before 'any version' end |
#too_new?(version) ⇒ Boolean
Check if the given version is too new (at or past the upper bound)
57 58 59 60 61 |
# File 'lib/git/version_constraint.rb', line 57 def too_new?(version) return false unless before version >= before end |
#too_old?(version) ⇒ Boolean
Check if the given version is too old (below the minimum)
45 46 47 48 49 |
# File 'lib/git/version_constraint.rb', line 45 def too_old?(version) return false unless min version < min end |