class RubyChecker::RubyChecker

RubyChecker is the main class for this gem. See the README.md on how to use it.

Public Class Methods

new(interpreter: ::RubyChecker::ANY, supported: nil) click to toggle source
# File lib/ruby_checker/ruby_checker.rb, line 30
def initialize(interpreter: ::RubyChecker::ANY, supported: nil)
  @interpreter = interpreter
  @supported   = supported
  @current     = Gem::Version.new(RUBY_VERSION)
end

Public Instance Methods

check!() click to toggle source

check! performs all the checks that are required.

# File lib/ruby_checker/ruby_checker.rb, line 37
def check!
  @supported = parsed_supported_version
  raise MissingSupportedVersionError if @supported.nil?

  res = perform_checks!
  Logger.new.debug "OK!" if res
  res
end

Protected Instance Methods

parsed_supported_version() click to toggle source

parsed_supported_version normalizes the @supported instance variable so it can be passed to the different checkers.

# File lib/ruby_checker/ruby_checker.rb, line 50
def parsed_supported_version
  return Gem::Version.new(@supported) if @supported.is_a?(String) && @supported != ""

  file = ruby_version_file
  return nil if file.nil? || !File.file?(file)

  Gem::Version.new(File.read(file).strip)
end
perform_checks!() click to toggle source

perform_checks! does the actual calls to the diferent checkers.

# File lib/ruby_checker/ruby_checker.rb, line 60
def perform_checks!
  Interpreter.new(@interpreter).check!
  Versions.new(current: @current, supported: @supported).check!
end
ruby_version_file() click to toggle source

ruby_version_file returns the path to the .ruby-version file if it can be guessed. Otherwise it returns nil.

# File lib/ruby_checker/ruby_checker.rb, line 67
def ruby_version_file
  return nil unless defined?(Rails)

  Rails.root.join(".ruby-version")
end