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
A new instance of 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
Returns a new instance of VersionConstraint.
31 32 33 |
# File 'lib/git/version_constraint.rb', line 31 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
65 66 67 |
# File 'lib/git/version_constraint.rb', line 65 def satisfied_by?(version) !too_old?(version) && !too_new?(version) end |
#to_s ⇒ String
Return a human-readable representation of this constraint
73 74 75 76 77 78 79 |
# File 'lib/git/version_constraint.rb', line 73 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)
53 54 55 56 57 |
# File 'lib/git/version_constraint.rb', line 53 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)
41 42 43 44 45 |
# File 'lib/git/version_constraint.rb', line 41 def too_old?(version) return false unless min version < min end |