Module: RuboCop::Cop::TargetRailsVersion

Overview

Common functionality for checking target rails version.

Constant Summary collapse

USES_REQUIRES_GEM_API =

Informs the base RuboCop gem that it the Rails version is checked via ‘requires_gem` API, without needing to call this `#support_target_rails_version` method.

true

Instance Method Summary collapse

Instance Method Details

#minimum_target_rails_version(version) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rubocop/cop/mixin/target_rails_version.rb', line 11

def minimum_target_rails_version(version)
  if respond_to?(:requires_gem)
    case version
    when Integer, Float then requires_gem(TARGET_GEM_NAME, ">= #{version}")
    when String then requires_gem(TARGET_GEM_NAME, version)
    end
  else
    # Fallback path for previous versions of RuboCop which don't support the `requires_gem` API yet.
    @minimum_target_rails_version = version
  end
end

#support_target_rails_version?(version) ⇒ Boolean

Returns:

  • (Boolean)


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

def support_target_rails_version?(version)
  if respond_to?(:requires_gem)
    return false unless gem_requirements

    gem_requirement = gem_requirements[TARGET_GEM_NAME]
    return true unless gem_requirement # If we have no requirement, then we support all versions

    gem_requirement.satisfied_by?(Gem::Version.new(version))
  else
    # Fallback path for previous versions of RuboCop which don't support the `requires_gem` API yet.
    @minimum_target_rails_version <= version
  end
end