Class: Yard::Lint::Validators::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/yard/lint/validators/base.rb

Overview

Base YARD validator class

Constant Summary collapse

DEFAULT_OPTIONS =

Default YARD command options that we need to use

[
  '--charset utf-8',
  '--markup markdown',
  '--no-progress'
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, selection) ⇒ Base

Returns a new instance of Base.

Parameters:

  • config (Yard::Lint::Config)

    configuration object

  • selection (Array<String>)

    array with ruby files we want to check



56
57
58
59
# File 'lib/yard/lint/validators/base.rb', line 56

def initialize(config, selection)
  @config = config
  @selection = selection
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



27
28
29
# File 'lib/yard/lint/validators/base.rb', line 27

def config
  @config
end

#selectionObject (readonly)

Returns the value of attribute selection.



27
28
29
# File 'lib/yard/lint/validators/base.rb', line 27

def selection
  @selection
end

Class Method Details

.clear_yard_database!void

This method returns an undefined value.

Clear the YARD database (primarily for testing)



47
48
49
50
51
# File 'lib/yard/lint/validators/base.rb', line 47

def clear_yard_database!
  return unless defined?(YARDOC_TEMP_DIR)

  FileUtils.rm_rf(Dir.glob(File.join(YARDOC_TEMP_DIR, '*')))
end

.command_cacheCommandCache

Lazy-initialized command cache shared across all validator instances This allows different validators to reuse results from identical YARD commands

Returns:



33
34
35
36
37
# File 'lib/yard/lint/validators/base.rb', line 33

def command_cache
  # Use Base's cache, not subclass's cache
  Base.instance_variable_get(:@shared_command_cache) ||
    Base.instance_variable_set(:@shared_command_cache, CommandCache.new)
end

.reset_command_cache!void

This method returns an undefined value.

Reset the command cache (primarily for testing)



41
42
43
# File 'lib/yard/lint/validators/base.rb', line 41

def reset_command_cache!
  Base.instance_variable_set(:@shared_command_cache, nil)
end

Instance Method Details

#callHash

Performs the validation and returns raw results

Returns:

  • (Hash)

    hash with stdout, stderr and exit_code keys



63
64
65
66
67
68
69
70
71
72
# File 'lib/yard/lint/validators/base.rb', line 63

def call
  # There might be a case when there were no files because someone ignored all
  # then we need to return empty result
  return raw if selection.nil? || selection.empty?

  # Anything that goes to shell needs to be escaped
  escaped_file_names = escape(selection).join(' ')

  yard_cmd(YARDOC_TEMP_DIR, escaped_file_names)
end