Module: RuboCop::Version
- Defined in:
- lib/rubocop/version.rb
Overview
This module holds the RuboCop version information.
Constant Summary collapse
- STRING =
'1.5.2'
- MSG =
'%<version>s (using Parser %<parser_version>s, '\ 'rubocop-ast %<rubocop_ast_version>s, ' \ 'running on %<ruby_engine>s %<ruby_version>s %<ruby_platform>s)'
- CANONICAL_FEATURE_NAMES =
{ 'Rspec' => 'RSpec' }.freeze
Class Method Summary collapse
- .document_version ⇒ Object private
- .extension_versions(env) ⇒ Object private
-
.feature_version(feature) ⇒ Object
private
Returns feature version in one of two ways:.
- .version(debug: false, env: nil) ⇒ Object private
Class Method Details
.document_version ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
75 76 77 |
# File 'lib/rubocop/version.rb', line 75 def self.document_version STRING.match('\d+\.\d+').to_s end |
.extension_versions(env) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rubocop/version.rb', line 36 def self.extension_versions(env) env.config_store.for_pwd.loaded_features.sort.map do |loaded_feature| next unless (match = loaded_feature.match(/rubocop-(?<feature>.*)/)) feature = match[:feature] begin require "rubocop/#{feature}/version" rescue LoadError # Not worth mentioning libs that are not installed else next unless (feature_version = feature_version(feature)) " - #{loaded_feature} #{feature_version}" end end.compact end |
.feature_version(feature) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns feature version in one of two ways:
-
Find by RuboCop core version style (e.g. rubocop-performance, rubocop-rspec)
-
Find by ‘bundle gem` version style (e.g. rubocop-rake)
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/rubocop/version.rb', line 59 def self.feature_version(feature) capitalized_feature = feature.capitalize extension_name = CANONICAL_FEATURE_NAMES.fetch(capitalized_feature, capitalized_feature) # Find by RuboCop core version style (e.g. rubocop-performance, rubocop-rspec) RuboCop.const_get(extension_name)::Version::STRING rescue NameError begin # Find by `bundle gem` version style (e.g. rubocop-rake, rubocop-packaging) RuboCop.const_get(extension_name)::VERSION rescue NameError # noop end end |
.version(debug: false, env: nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rubocop/version.rb', line 15 def self.version(debug: false, env: nil) if debug verbose_version = format(MSG, version: STRING, parser_version: Parser::VERSION, rubocop_ast_version: RuboCop::AST::Version::STRING, ruby_engine: RUBY_ENGINE, ruby_version: RUBY_VERSION, ruby_platform: RUBY_PLATFORM) return verbose_version unless env extension_versions = extension_versions(env) return verbose_version if extension_versions.empty? <<~VERSIONS #{verbose_version} #{extension_versions.join("\n")} VERSIONS else STRING end end |