Module: RuboCop::Cop::TargetRailsVersion
- Included in:
- Rails::ActionControllerTestCase, Rails::ApplicationJob, Rails::ApplicationMailer, Rails::ApplicationRecord, Rails::BelongsTo, Rails::CompactBlank, Rails::ContentTag, Rails::EnumSyntax, Rails::EnvLocal, Rails::ExpandedDateRange, Rails::FreezeTime, Rails::HttpPositionalArguments, Rails::IndexWith, Rails::Pick, Rails::Pluck, Rails::RedundantPresenceValidationOnBelongsTo, Rails::RedundantTravelBack, Rails::RequireDependency, Rails::ResponseParsedBody, Rails::ToFormattedS, Rails::ToSWithArgument, Rails::TopLevelHashWithIndifferentAccess, Rails::WhereMissing, Rails::WhereRange
- Defined in:
- lib/rubocop/cop/mixin/target_rails_version.rb
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
- TARGET_GEM_NAME =
Look for ‘railties` instead of `rails`, to support apps that only use a subset of `rails` See github.com/rubocop/rubocop/pull/11289
'railties'
Instance Method Summary collapse
-
#minimum_target_rails_version(version) ⇒ Object
:nodoc:.
- #support_target_rails_version?(version) ⇒ Boolean
Instance Method Details
#minimum_target_rails_version(version) ⇒ Object
:nodoc:
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rubocop/cop/mixin/target_rails_version.rb', line 14 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
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rubocop/cop/mixin/target_rails_version.rb', line 26 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 |