class RuboCop::TargetRuby::BundlerLockFile
The lock file of Bundler may identify the target ruby version. @api private
Public Instance Methods
name()
click to toggle source
# File lib/rubocop/target_ruby.rb, line 192 def name "`#{bundler_lock_file_path}`" end
Private Instance Methods
bundler_lock_file_path()
click to toggle source
# File lib/rubocop/target_ruby.rb, line 225 def bundler_lock_file_path @config.bundler_lock_file_path end
find_version()
click to toggle source
# File lib/rubocop/target_ruby.rb, line 198 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