Class: SidekiqUniqueJobs::VersionCheck
- Inherits:
-
Object
- Object
- SidekiqUniqueJobs::VersionCheck
- Defined in:
- lib/sidekiq_unique_jobs/version_check.rb
Overview
Handles checking if a version is compliant with given constraint
Constant Summary collapse
- PATTERN =
rubocop:disable Layout/LineLength, Lint/MixedRegexpCaptureTypes
/(?<operator1>[<>=]+)?\s?(?<version1>(\d+.?)+)(\s+&&\s+)?(?<operator2>[<>=]+)?\s?(?<version2>(\d+.?)+)?/m.freeze
Instance Attribute Summary collapse
-
#match ⇒ Object
readonly
Returns the value of attribute match.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
-
.satisfied?(version, constraint) ⇒ true, false
Checks if a version is constraint is satisfied.
-
.unfulfilled?(version, constraint) ⇒ true, false
Checks if a version is constraint is unfulfilled.
Instance Method Summary collapse
-
#initialize(version, constraint) ⇒ VersionCheck
constructor
Initialize a new VersionCheck instance.
-
#satisfied? ⇒ true, false
Checks if all constraints were met.
Constructor Details
#initialize(version, constraint) ⇒ VersionCheck
Initialize a new VersionCheck instance
65 66 67 68 69 70 71 |
# File 'lib/sidekiq_unique_jobs/version_check.rb', line 65 def initialize(version, constraint) @version = Gem::Version.new(version) @match = PATTERN.match(constraint.to_s) raise ArgumentError, "A version (eg. 5.0) is required to compare against" unless @version raise ArgumentError, "At least one operator and version is required (eg. >= 5.1)" unless constraint end |
Instance Attribute Details
#match ⇒ Object (readonly)
Returns the value of attribute match.
57 58 59 |
# File 'lib/sidekiq_unique_jobs/version_check.rb', line 57 def match @match end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
53 54 55 |
# File 'lib/sidekiq_unique_jobs/version_check.rb', line 53 def version @version end |
Class Method Details
.satisfied?(version, constraint) ⇒ true, false
Checks if a version is constraint is satisfied
27 28 29 |
# File 'lib/sidekiq_unique_jobs/version_check.rb', line 27 def self.satisfied?(version, constraint) new(version, constraint).satisfied? end |
.unfulfilled?(version, constraint) ⇒ true, false
Checks if a version is constraint is unfulfilled
46 47 48 |
# File 'lib/sidekiq_unique_jobs/version_check.rb', line 46 def self.unfulfilled?(version, constraint) !satisfied?(version, constraint) end |
Instance Method Details
#satisfied? ⇒ true, false
Checks if all constraints were met
79 80 81 82 83 |
# File 'lib/sidekiq_unique_jobs/version_check.rb', line 79 def satisfied? constraints.all? do |expected, operator| compare(expected, operator) end end |