Class: RuboCop::Schema::DocumentLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/schema/document_loader.rb

Constant Summary collapse

DOCS_URL_TEMPLATE =
-'https://raw.githubusercontent.com/rubocop/%s/%s/docs/modules/ROOT/pages/cops%s.adoc'
DEFAULTS_URL_TEMPLATE =
-'https://raw.githubusercontent.com/rubocop/%s/%s/config/default.yml'
CORRECTIONS =
{
  'rubocop' => {
    # Fixes a typo that causes Asciidoctor to crash
    '1.10.0' => '174bda389c2c23cffb17e9d6128f5e6bdbc0e8a0'
  }
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(http_client) ⇒ DocumentLoader

Returns a new instance of DocumentLoader.

Parameters:



20
21
22
23
24
# File 'lib/rubocop/schema/document_loader.rb', line 20

def initialize(http_client)
  @http_client = http_client
  @docs        = {}
  @defaults    = {}
end

Instance Method Details

#defaults(spec) ⇒ Object

Parameters:



27
28
29
30
# File 'lib/rubocop/schema/document_loader.rb', line 27

def defaults(spec)
  @defaults[spec] ||=
    YAML.safe_load @http_client.get(url_for_defaults(spec)), [Regexp, Symbol], [], true
end

#doc(spec, department = nil) ⇒ Asciidoctor::Document

Parameters:

  • spec (Spec)
  • department (String) (defaults to: nil)

Returns:

  • (Asciidoctor::Document)


35
36
37
38
# File 'lib/rubocop/schema/document_loader.rb', line 35

def doc(spec, department = nil)
  @docs[[spec, department]] ||=
    Asciidoctor.load @http_client.get url_for_doc(spec, department)
end