Method: Solargraph::Diagnostics::RubocopHelpers.require_rubocop
- Defined in:
- lib/solargraph/diagnostics/rubocop_helpers.rb
.require_rubocop(version = nil) ⇒ Object
Requires a specific version of rubocop, or the latest installed version if version is ‘nil`.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/solargraph/diagnostics/rubocop_helpers.rb', line 15 def require_rubocop(version = nil) begin gem_path = Gem::Specification.find_by_name('rubocop', version).full_gem_path gem_lib_path = File.join(gem_path, 'lib') $LOAD_PATH.unshift(gem_lib_path) unless $LOAD_PATH.include?(gem_lib_path) # @todo Gem::MissingSpecVersionError is undocumented for some reason # @sg-ignore rescue Gem::MissingSpecVersionError => e raise InvalidRubocopVersionError, "could not find '#{e.name}' (#{e.requirement}) - "\ "did find: [#{e.specs.map { |s| s.version.version }.join(', ')}]" end require 'rubocop' end |