class RuboCop::TargetRuby::GemspecFile
The target ruby version may be found in a .gemspec file. @api private
Constants
- GEMSPEC_EXTENSION
Public Instance Methods
name()
click to toggle source
# File lib/rubocop/target_ruby.rb, line 162 def name "`required_ruby_version` parameter (in #{gemspec_filename})" end
Private Instance Methods
find_default_minimal_known_ruby(right_hand_side)
click to toggle source
# File lib/rubocop/target_ruby.rb, line 209 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()
click to toggle source
# File lib/rubocop/target_ruby.rb, line 168 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
gemspec_filename()
click to toggle source
# File lib/rubocop/target_ruby.rb, line 178 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()
click to toggle source
# File lib/rubocop/target_ruby.rb, line 185 def gemspec_filepath @gemspec_filepath ||= @config.find_file_upwards(gemspec_filename, @config.base_dir_for_path_parameters) end
version_from_array(array)
click to toggle source
# File lib/rubocop/target_ruby.rb, line 205 def version_from_array(array) array.children.map(&:value) end
version_from_gemspec_file(file)
click to toggle source
# File lib/rubocop/target_ruby.rb, line 190 def version_from_gemspec_file(file) processed_source = ProcessedSource.from_file(file, DEFAULT_VERSION) required_ruby_version(processed_source.ast).first end
version_from_right_hand_side(right_hand_side)
click to toggle source
# File lib/rubocop/target_ruby.rb, line 195 def version_from_right_hand_side(right_hand_side) if right_hand_side.array_type? version_from_array(right_hand_side) elsif gem_requirement?(right_hand_side) right_hand_side.children.last.value else right_hand_side.value end end