Class: RuboCop::TargetRuby::BundlerLockFile Private

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Source
Instance Chain:
self, Source
Inherits: RuboCop::TargetRuby::Source
Defined in: lib/rubocop/target_ruby.rb


The lock file of Bundler may identify the target ruby version.

Class Method Summary

Source - Inherited

Instance Attribute Summary

Source - Inherited

Instance Method Summary

Source - Inherited

Instance Method Details

#bundler_lock_file_path (private)

[ GitHub ]

# File 'lib/rubocop/target_ruby.rb', line 221

def bundler_lock_file_path

#find_version (private)

[ GitHub ]

# File 'lib/rubocop/target_ruby.rb', line 194

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


[ GitHub ]

# File 'lib/rubocop/target_ruby.rb', line 188

def name