Class: RuboCop::TargetRuby::GemspecFile Private
Do not use. This class is for internal use only.
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Macros,
Source
|
|
Instance Chain:
self,
Source
|
|
Inherits: |
RuboCop::TargetRuby::Source
|
Defined in: | lib/rubocop/target_ruby.rb |
Overview
The target ruby version may be found in a .gemspec file.
Constant Summary
-
GEMSPEC_EXTENSION =
# File 'lib/rubocop/target_ruby.rb', line 56'.gemspec'
Class Method Summary
Instance Attribute Summary
Instance Method Summary
- #gem_requirement_versions(node)
- #name Internal use only
- #required_ruby_version(node)
- #find_default_minimal_known_ruby(right_hand_side) private Internal use only
- #find_version private Internal use only
- #gemspec_filename private Internal use only
- #gemspec_filepath private Internal use only
- #version_from_array(array) private Internal use only
- #version_from_gemspec_file(file) private Internal use only
- #version_from_right_hand_side(right_hand_side) private Internal use only
Source
- Inherited
Instance Method Details
#find_default_minimal_known_ruby(right_hand_side) (private)
[ GitHub ]# File 'lib/rubocop/target_ruby.rb', line 121
def find_default_minimal_known_ruby(right_hand_side) version = version_from_right_hand_side(right_hand_side) requirement = Gem::Requirement.new(version) KNOWN_RUBIES.detect do |v| v >= DEFAULT_VERSION && requirement.satisfied_by?(Gem::Version.new("#{v}.99")) end end
#find_version (private)
[ GitHub ]# File 'lib/rubocop/target_ruby.rb', line 76
def find_version file = gemspec_filepath return unless file && File.file?(file) right_hand_side = version_from_gemspec_file(file) return if right_hand_side.nil? find_default_minimal_known_ruby(right_hand_side) end
#gem_requirement_versions(node)
[ GitHub ]# File 'lib/rubocop/target_ruby.rb', line 64
def_node_matcher :gem_requirement_versions, <<~PATTERN (send (const(const _ :Gem):Requirement) :new {$str+ | (send $str :freeze)+ | (array $str+) | (array (send $str :freeze)+)} ) PATTERN
#gemspec_filename (private)
[ GitHub ]# File 'lib/rubocop/target_ruby.rb', line 86
def gemspec_filename @gemspec_filename ||= begin basename = Pathname.new(@config.base_dir_for_path_parameters).basename.to_s "#{basename}#{GEMSPEC_EXTENSION}" end end
#gemspec_filepath (private)
[ GitHub ]# File 'lib/rubocop/target_ruby.rb', line 93
def gemspec_filepath @gemspec_filepath ||= @config.find_file_upwards(gemspec_filename, @config.base_dir_for_path_parameters) end
#name
[ GitHub ]# File 'lib/rubocop/target_ruby.rb', line 70
def name "`required_ruby_version` parameter (in #{gemspec_filename})" end
#required_ruby_version(node)
[ GitHub ]# File 'lib/rubocop/target_ruby.rb', line 59
def_node_search :required_ruby_version, <<~PATTERN (send _ :required_ruby_version= $_) PATTERN
#version_from_array(array) (private)
[ GitHub ]# File 'lib/rubocop/target_ruby.rb', line 117
def version_from_array(array) array.children.map(&:value) end
#version_from_gemspec_file(file) (private)
[ GitHub ]# File 'lib/rubocop/target_ruby.rb', line 98
def version_from_gemspec_file(file) processed_source = ProcessedSource.from_file( file, DEFAULT_VERSION, parser_engine: @config.parser_engine ) required_ruby_version(processed_source.ast).first end
#version_from_right_hand_side(right_hand_side) (private)
[ GitHub ]# File 'lib/rubocop/target_ruby.rb', line 105
def version_from_right_hand_side(right_hand_side) gem_requirement_versions = gem_requirement_versions(right_hand_side) if right_hand_side.array_type? && right_hand_side.children.all?(&:str_type?) version_from_array(right_hand_side) elsif gem_requirement_versions gem_requirement_versions.map(&:value) elsif right_hand_side.str_type? right_hand_side.value end end