Class: Solargraph::LanguageServer::Message::Extended::CheckGemVersion
- Defined in:
- lib/solargraph/language_server/message/extended/check_gem_version.rb
Overview
Check if a more recent version of the Solargraph gem is available. Notify the client when an update exists. If the ‘verbose` parameter is true, notify the client when the gem is up to date.
Constant Summary collapse
- GEM_ZERO =
Gem::Version.new('0.0.0')
Instance Attribute Summary
Attributes inherited from Base
#host, #id, #method, #params, #request, #result
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(host, request, current: Gem::Version.new(Solargraph::VERSION), available: nil) ⇒ CheckGemVersion
constructor
A new instance of CheckGemVersion.
- #process ⇒ Object
Methods inherited from Base
#post_initialize, #send_response, #set_error, #set_result
Constructor Details
#initialize(host, request, current: Gem::Version.new(Solargraph::VERSION), available: nil) ⇒ CheckGemVersion
Returns a new instance of CheckGemVersion.
24 25 26 27 28 |
# File 'lib/solargraph/language_server/message/extended/check_gem_version.rb', line 24 def initialize host, request, current: Gem::Version.new(Solargraph::VERSION), available: nil super(host, request) @current = current @available = available end |
Class Method Details
.fetcher ⇒ Object
14 15 16 |
# File 'lib/solargraph/language_server/message/extended/check_gem_version.rb', line 14 def self.fetcher @fetcher ||= Gem::SpecFetcher.new end |
.fetcher=(obj) ⇒ Object
18 19 20 |
# File 'lib/solargraph/language_server/message/extended/check_gem_version.rb', line 18 def self.fetcher= obj @fetcher = obj end |
Instance Method Details
#process ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/solargraph/language_server/message/extended/check_gem_version.rb', line 30 def process if available > GEM_ZERO if available > current host. "Solargraph gem version #{available} is available. (Current version: #{current})", LanguageServer::MessageTypes::INFO, ['Update now'] do |result| next unless result == 'Update now' cmd = if host.['useBundler'] 'bundle update solargraph' else 'gem update solargraph' end o, s = Open3.capture2(cmd) if s == 0 host. 'Successfully updated the Solargraph gem.', LanguageServer::MessageTypes::INFO host.send_notification '$/solargraph/restart', {} else host. 'An error occurred while updating the gem.', LanguageServer::MessageTypes::ERROR end end elsif params['verbose'] host. "The Solargraph gem is up to date (version #{Solargraph::VERSION})." end elsif fetched? Solargraph::Logging.logger.warn error host.(error, MessageTypes::ERROR) if params['verbose'] end set_result({ installed: current, available: available }) end |