Module: RuboCop::Cop::Documentation

Included in:
CopsDocumentationGenerator
Defined in:
lib/rubocop/cop/documentation.rb

Overview

Helpers for builtin documentation

Class Method Summary collapse

Class Method Details

.base_url_for(cop_class, config) ⇒ 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.

 25 26 27 28 29 30 31 32 33
# File 'lib/rubocop/cop/documentation.rb', line 25 def base_url_for(cop_class, config) if config department_name = cop_class.department.to_s url = config.for_department(department_name)['DocumentationBaseURL'] return url if url end default_base_url if builtin?(cop_class) end

.builtin?(cop_class) ⇒ Boolean

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:

  • (Boolean)
 57 58 59 60 61 62 63
# File 'lib/rubocop/cop/documentation.rb', line 57 def builtin?(cop_class) # any custom method will do  return false unless (m = cop_class.instance_methods(false).first) path, _line = cop_class.instance_method(m).source_location path.start_with?(__dir__) end

.default_base_urlObject

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.

 47 48 49
# File 'lib/rubocop/cop/documentation.rb', line 47 def default_base_url 'https://docs.rubocop.org/rubocop' end

.default_extensionObject

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.

 52 53 54
# File 'lib/rubocop/cop/documentation.rb', line 52 def default_extension '.html' end

.department_to_basename(department) ⇒ 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.

 10 11 12
# File 'lib/rubocop/cop/documentation.rb', line 10 def department_to_basename(department) "cops_#{department.to_s.downcase.tr('/', '_')}" end

.extension_for(cop_class, config) ⇒ 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
# File 'lib/rubocop/cop/documentation.rb', line 36 def extension_for(cop_class, config) if config department_name = cop_class.department extension = config.for_department(department_name)['DocumentationExtension'] return extension if extension end default_extension end

.url_for(cop_class, config = 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
# File 'lib/rubocop/cop/documentation.rb', line 15 def url_for(cop_class, config = nil) base = department_to_basename(cop_class.department) fragment = cop_class.cop_name.downcase.gsub(/[^a-z]/, '') base_url = base_url_for(cop_class, config) extension = extension_for(cop_class, config) "#{base_url}/#{base}#{extension}##{fragment}" if base_url end