Module: RuboCop::Cop::Sorbet::TargetSorbetVersion
- Included in:
- BuggyObsoleteStrictMemoization, ObsoleteStrictMemoization
- Defined in:
- lib/rubocop/cop/sorbet/mixin/target_sorbet_version.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #enabled_for_sorbet_static_version? ⇒ Boolean
- #read_sorbet_static_version_from_bundler_lock_file ⇒ Object
- #sorbet_enabled? ⇒ Boolean
- #target_sorbet_static_version_from_bundler_lock_file ⇒ Object
Class Method Details
.included(target) ⇒ Object
8 9 10 |
# File 'lib/rubocop/cop/sorbet/mixin/target_sorbet_version.rb', line 8 def included(target) target.extend(ClassMethods) end |
Instance Method Details
#enabled_for_sorbet_static_version? ⇒ Boolean
28 29 30 31 32 33 |
# File 'lib/rubocop/cop/sorbet/mixin/target_sorbet_version.rb', line 28 def enabled_for_sorbet_static_version? sorbet_static_version = target_sorbet_static_version_from_bundler_lock_file return false unless sorbet_static_version self.class.supports_target_sorbet_static_version?(sorbet_static_version) end |
#read_sorbet_static_version_from_bundler_lock_file ⇒ Object
44 45 46 47 48 49 |
# File 'lib/rubocop/cop/sorbet/mixin/target_sorbet_version.rb', line 44 def read_sorbet_static_version_from_bundler_lock_file require "bundler" ::Bundler.locked_gems.specs.find { |spec| spec.name == "sorbet-static" }&.version rescue LoadError, ::Bundler::GemfileNotFound nil end |
#sorbet_enabled? ⇒ Boolean
24 25 26 |
# File 'lib/rubocop/cop/sorbet/mixin/target_sorbet_version.rb', line 24 def sorbet_enabled? !target_sorbet_static_version_from_bundler_lock_file.nil? end |
#target_sorbet_static_version_from_bundler_lock_file ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/rubocop/cop/sorbet/mixin/target_sorbet_version.rb', line 35 def target_sorbet_static_version_from_bundler_lock_file # Do memoization with the `defined?` pattern since sorbet-static version might be `nil` if defined?(@target_sorbet_static_version_from_bundler_lock_file) @target_sorbet_static_version_from_bundler_lock_file else @target_sorbet_static_version_from_bundler_lock_file = read_sorbet_static_version_from_bundler_lock_file end end |