Class: Inch::SourceParser

Inherits:
Object
  • Object
show all
Defined in:
lib/inch/source_parser.rb

Overview

Parses the source tree (using YARD)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run(*args) ⇒ SourceParser

Helper method to run an instance with the given args

Returns:

See Also:



8
9
10
11
12
# File 'lib/inch/source_parser.rb', line 8

def self.run(*args)
  parser = self.new
  parser.run(*args)
  parser
end

Instance Method Details

#all_objectsArray<CodeObject::Proxy::Base>

Returns all parsed objects as code object proxies

Returns:

See Also:



18
19
20
21
22
# File 'lib/inch/source_parser.rb', line 18

def all_objects
  @all_objects ||= all_parsed_objects.map do |o|
    CodeObject::Proxy.for(o)
  end.sort_by(&:path)
end

#find_object(path) ⇒ CodeObject::Proxy::Base Also known as: []

Returns the object with the given path

Examples:


SourceParser.find_objects("Foo#bar")
# => returns code object proxy for Foo#bar

Parameters:

  • path (String)

    partial path/name of an object

Returns:



33
34
35
# File 'lib/inch/source_parser.rb', line 33

def find_object(path)
  all_objects.detect { |o| o.path == path }
end

#find_objects(path) ⇒ Array<CodeObject::Proxy::Base>

Returns all objects where the path starts_with the given path

Examples:


SourceParser.find_objects("Foo#")
# => returns code object proxies for all instance methods of Foo

Parameters:

  • path (String)

    partial path/name of an object

Returns:



47
48
49
# File 'lib/inch/source_parser.rb', line 47

def find_objects(path)
  all_objects.select { |o| o.path.start_with?(path) }
end

#run(paths, excluded = []) ⇒ Object



51
52
53
54
# File 'lib/inch/source_parser.rb', line 51

def run(paths, excluded = [])
  YARD::Registry.clear
  YARD.parse(paths, excluded)
end