Class: CopsDocumentationGenerator Private
- Inherits:
-
Object
- Object
- CopsDocumentationGenerator
- Includes:
- RuboCop::Cop::Documentation
- Defined in:
- lib/rubocop/cops_documentation_generator.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Class for generating documentation of all cops departments
Defined Under Namespace
Classes: CopData
Constant Summary collapse
- STRUCTURE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ name: ->(data) { cop_header(data.cop) }, required_ruby_version: ->(data) { required_ruby_version(data.cop) }, properties: ->(data) { properties(data.cop) }, description: ->(data) { "#{data.description}\n" }, safety: ->(data) { safety_object(data.safety_objects, data.cop) }, examples: ->(data) { examples(data.example_objects, data.cop) }, configuration: ->(data) { configurations(data.cop.department, data.config, data.cop) }, references: ->(data) { references(data.cop, data.see_objects) } }.freeze
Instance Method Summary collapse
- #call ⇒ Object private
-
#initialize(departments: [], extra_info: {}, base_dir: Dir.pwd) ⇒ CopsDocumentationGenerator
constructor
private
This class will only generate documentation for cops that belong to one of the departments given in the ‘departments` array.
Methods included from RuboCop::Cop::Documentation
base_url_for, builtin?, default_base_url, default_extension, department_to_basename, extension_for, url_for
Constructor Details
#initialize(departments: [], extra_info: {}, base_dir: Dir.pwd) ⇒ CopsDocumentationGenerator
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.
This class will only generate documentation for cops that belong to one of the departments given in the ‘departments` array. E.g. if we only wanted documentation for Lint cops:
CopsDocumentationGenerator.new(departments: ['Lint']).call
You can append additional information:
callback = ->(data) { required_rails_version(data.cop) }
CopsDocumentationGenerator.new(extra_info: { ruby_version: callback }).call
This will insert the string returned from the lambda after the section from RuboCop itself. See ‘CopsDocumentationGenerator::STRUCTURE` for available sections.
39 40 41 42 43 44 45 46 47 |
# File 'lib/rubocop/cops_documentation_generator.rb', line 39 def initialize(departments: [], extra_info: {}, base_dir: Dir.pwd) @departments = departments.map(&:to_sym).sort! @extra_info = extra_info @cops = RuboCop::Cop::Registry.global @config = RuboCop::ConfigLoader.default_configuration @base_dir = base_dir @docs_path = "#{base_dir}/docs/modules/ROOT" FileUtils.mkdir_p("#{@docs_path}/pages") end |
Instance Method Details
#call ⇒ 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.
49 50 51 52 53 54 55 56 |
# File 'lib/rubocop/cops_documentation_generator.rb', line 49 def call YARD::Registry.load! departments.each { |department| print_cops_of_department(department) } print_table_of_contents ensure RuboCop::ConfigLoader.default_configuration = nil end |