class VCR::VersionChecker

@private

Public Class Methods

new(library_name, library_version, min_patch_level, max_minor_version) click to toggle source
# File lib/vcr/util/version_checker.rb, line 4
def initialize(library_name, library_version, min_patch_level, max_minor_version)
  @library_name, @library_version = library_name, library_version
  @min_patch_level, @max_minor_version = min_patch_level, max_minor_version

  @major,     @minor,     @patch     = parse_version(library_version)
  @min_major, @min_minor, @min_patch = parse_version(min_patch_level)
  @max_major, @max_minor             = parse_version(max_minor_version)

  @comparison_result = compare_version
end

Public Instance Methods

check_version!() click to toggle source
# File lib/vcr/util/version_checker.rb, line 15
def check_version!
  raise_too_low_error if too_low?
  warn_about_too_high if too_high?
end

Private Instance Methods

compare_version() click to toggle source
# File lib/vcr/util/version_checker.rb, line 42
def compare_version
  case
    when @major < @min_major then :too_low
    when @major > @max_major then :too_high
    when @major > @min_major then :ok
    when @minor < @min_minor then :too_low
    when @minor > @max_minor then :too_high
    when @minor > @min_minor then :ok
    when @patch < @min_patch then :too_low
  end
end
parse_version(version) click to toggle source
# File lib/vcr/util/version_checker.rb, line 58
def parse_version(version)
  version.split('.').map { |v| v.to_i }
end
raise_too_low_error() click to toggle source
# File lib/vcr/util/version_checker.rb, line 30
def raise_too_low_error
  raise Errors::LibraryVersionTooLowError,
    "You are using #{@library_name} #{@library_version}. " +
    "VCR requires version #{version_requirement}."
end
too_high?() click to toggle source
# File lib/vcr/util/version_checker.rb, line 26
def too_high?
  @comparison_result == :too_high
end
too_low?() click to toggle source
# File lib/vcr/util/version_checker.rb, line 22
def too_low?
  @comparison_result == :too_low
end
version_requirement() click to toggle source
# File lib/vcr/util/version_checker.rb, line 54
def version_requirement
  ">= #{@min_patch_level}, < #{@max_major}.#{@max_minor + 1}"
end
warn_about_too_high() click to toggle source
# File lib/vcr/util/version_checker.rb, line 36
def warn_about_too_high
  Kernel.warn "You are using #{@library_name} #{@library_version}. " +
              "VCR is known to work with #{@library_name} #{version_requirement}. " +
              "It may not work with this version."
end