Module: RuboCop::Cop::TargetRubyVersion

Overview

Common functionality for checking target ruby version.

Instance Method Summary collapse

Instance Method Details

#maximum_target_ruby_version(version) ⇒ Object



19
20
21
# File 'lib/rubocop/cop/mixin/target_ruby_version.rb', line 19

def maximum_target_ruby_version(version)
  @maximum_target_ruby_version = version
end

#minimum_target_ruby_version(version) ⇒ Object



15
16
17
# File 'lib/rubocop/cop/mixin/target_ruby_version.rb', line 15

def minimum_target_ruby_version(version)
  @minimum_target_ruby_version = version
end

#required_maximum_ruby_versionObject



11
12
13
# File 'lib/rubocop/cop/mixin/target_ruby_version.rb', line 11

def required_maximum_ruby_version
  @maximum_target_ruby_version
end

#required_minimum_ruby_versionObject



7
8
9
# File 'lib/rubocop/cop/mixin/target_ruby_version.rb', line 7

def required_minimum_ruby_version
  @minimum_target_ruby_version
end

#support_target_ruby_version?(version) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rubocop/cop/mixin/target_ruby_version.rb', line 23

def support_target_ruby_version?(version)
  # By default, no minimum or maximum versions of ruby are required
  # to run any cop. In order to do a simple numerical comparison of
  # the requested version against any requirements, we use 0 and
  # Infinity as the default values to indicate no minimum (0) and no
  # maximum (Infinity).
  min = required_minimum_ruby_version || 0
  max = required_maximum_ruby_version || Float::INFINITY

  min <= version && max >= version
end