Method: YARD::Parser::SourceParser.before_parse_file

Defined in:
lib/yard/parser/source_parser.rb

.before_parse_file {|parser| ... } ⇒ Proc

Registers a callback to be called before an individual file is parsed. The block passed to this method will be called on subsequent parse calls.

To register a callback that is called before the entire list of files is processed, see before_parse_list.

Examples:

Installing a simple callback

SourceParser.before_parse_file do |parser|
  puts "I'm parsing #{parser.file}"
end
YARD.parse('lib/**/*.rb')
# prints:
"I'm parsing lib/foo.rb"
"I'm parsing lib/foo_bar.rb"
"I'm parsing lib/last_file.rb"

Cancel parsing of any test_*.rb files

SourceParser.before_parse_file do |parser|
  return false if parser.file =~ /^test_.+\.rb$/
end

Yields:

  • (parser)

    the yielded block is called once before each file that is parsed. This might happen many times for a single codebase.

Yield Parameters:

Yield Returns:

  • (Boolean)

    if the block returns false, parsing for the file is cancelled.

Returns:

  • (Proc)

    the yielded block

See Also:

Since:

  • 0.7.0

[View source]

292
293
294
# File 'lib/yard/parser/source_parser.rb', line 292

def before_parse_file(&block)
  before_parse_file_callbacks << block
end