class RuboCop::TargetRuby::BundlerLockFile
@api private
The lock file of Bundler may identify the target ruby version.
def bundler_lock_file_path
def bundler_lock_file_path @config.bundler_lock_file_path end
def find_version
def find_version lock_file_path = bundler_lock_file_path return nil unless lock_file_path in_ruby_section = false File.foreach(lock_file_path) do |line| # If ruby is in Gemfile.lock or gems.lock, there should be two lines # towards the bottom of the file that look like: # RUBY VERSION # ruby W.X.YpZ # We ultimately want to match the "ruby W.X.Y.pZ" line, but there's # extra logic to make sure we only start looking once we've seen the # "RUBY VERSION" line. in_ruby_section ||= line.match(/^\s*RUBY\s*VERSION\s*$/) next unless in_ruby_section # We currently only allow this feature to work with MRI ruby. If # jruby (or something else) is used by the project, it's lock file # will have a line that looks like: # RUBY VERSION # ruby W.X.YpZ (jruby x.x.x.x) # The regex won't match in this situation. result = line.match(/^\s*ruby\s+(\d+\.\d+)[p.\d]*\s*$/) return result.captures.first.to_f if result end end
def name
def name "`#{bundler_lock_file_path}`" end