class WebMock::VersionChecker

Public Class Methods

new(library_name, library_version, min_patch_level, max_minor_version = nil) click to toggle source
# File lib/webmock/util/version_checker.rb, line 6
def initialize(library_name, library_version, min_patch_level, max_minor_version = nil)
  @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) if max_minor_version

  @comparison_result = compare_version
end

Public Instance Methods

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

Private Instance Methods

colorize(text, color_code) click to toggle source
# File lib/webmock/util/version_checker.rb, line 69
def colorize(text, color_code)
  "#{color_code}#{text}\e[0m"
end
compare_version() click to toggle source
# File lib/webmock/util/version_checker.rb, line 47
def compare_version
  case
    when @major < @min_major then :too_low
    when @max_major && @major > @max_major then :too_high
    when @major > @min_major then :ok
    when @minor < @min_minor then :too_low
    when @max_minor && @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/webmock/util/version_checker.rb, line 65
def parse_version(version)
  version.split('.').map { |v| v.to_i }
end
too_high?() click to toggle source
# File lib/webmock/util/version_checker.rb, line 28
def too_high?
  @comparison_result == :too_high
end
too_low?() click to toggle source
# File lib/webmock/util/version_checker.rb, line 24
def too_low?
  @comparison_result == :too_low
end
version_requirement() click to toggle source
# File lib/webmock/util/version_checker.rb, line 59
def version_requirement
  req = ">= #{@min_patch_level}"
  req += ", < #{@max_major}.#{@max_minor + 1}" if @max_minor
  req
end
warn_about_too_high() click to toggle source
# File lib/webmock/util/version_checker.rb, line 37
def warn_about_too_high
  warn_in_red "You are using #{@library_name} #{@library_version}. " +
              "WebMock is known to work with #{@library_name} #{version_requirement}. " +
              "It may not work with this version."
end
warn_about_too_low() click to toggle source
# File lib/webmock/util/version_checker.rb, line 32
def warn_about_too_low
  warn_in_red "You are using #{@library_name} #{@library_version}. " +
              "WebMock supports version #{version_requirement}."
end
warn_in_red(text) click to toggle source
# File lib/webmock/util/version_checker.rb, line 43
def warn_in_red(text)
  Kernel.warn colorize(text, "\e[31m")
end