Sha256: b75449a493e59fe9b3fbd6f9d7d3f0f43473ffa479c9698891603ac3cf9663b7
Contents?: true
Size: 1.6 KB
Versions: 6
Compression:
Stored size: 1.6 KB
Contents
# frozen_string_literal: true module RuboCop module Cop # Common functionality for checking target rails version. module TargetRailsVersion # 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. USES_REQUIRES_GEM_API = true 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 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 # Look for `railties` instead of `rails`, to support apps that only use a subset of `rails` # See https://github.com/rubocop/rubocop/pull/11289 TARGET_GEM_NAME = 'railties' private_constant :TARGET_GEM_NAME end end end
Version data entries
6 entries across 6 versions & 3 rubygems