Class: FileParser

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

Overview

Parses code in a file

Constant Summary collapse

RUNNABLE_TAG =
:runnable

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ FileParser

Parse file with #YARD::CLI::Stats

Parameters:

  • file_path (String)

    path to the file to be parsed

Raises:



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/file_parser.rb', line 16

def initialize(file_path)
  raise ConsoleRunnerError "Cannot find file #{file_path}" unless File.exist?(file_path)
  code = YARD::CLI::Stats.new
  code.run(file_path)
  @all_objects     = code.all_objects
  runnable_classes = list_classes(:runnable)
  raise ConsoleRunnerError, 'At least one runnable Class should be specified in file' if runnable_classes.count != 1
  @clazz             = runnable_classes.first
  all_methods        = list_methods(:all, clazz)
  @runnable_methods  = list_methods(:runnable, clazz)
  @initialize_method = all_methods.find { |m| m.name == :initialize }
  @run_method        = all_methods.find { |m| m.name == :run }
end

Instance Attribute Details

#clazzObject (readonly)

Returns the value of attribute clazz.



8
9
10
# File 'lib/file_parser.rb', line 8

def clazz
  @clazz
end

#initialize_methodObject (readonly)

Returns the value of attribute initialize_method.



8
9
10
# File 'lib/file_parser.rb', line 8

def initialize_method
  @initialize_method
end

#run_methodObject (readonly)

Returns the value of attribute run_method.



8
9
10
# File 'lib/file_parser.rb', line 8

def run_method
  @run_method
end

#runnable_methodsObject (readonly)

Returns the value of attribute runnable_methods.



8
9
10
# File 'lib/file_parser.rb', line 8

def runnable_methods
  @runnable_methods
end

Class Method Details

.select_runnable_tags(yard_object) ⇒ Array(YARD::Tags::Tag)

Select all @runnable tags from of specified object

Parameters:

  • yard_object (YARD::CodeObjects::MethodObject, YARD::CodeObjects::ClassObject)

    YARD object

Returns:

  • (Array(YARD::Tags::Tag))


34
35
36
# File 'lib/file_parser.rb', line 34

def self.select_runnable_tags(yard_object)
  yard_object.tags.select { |t| t.tag_name == RUNNABLE_TAG.to_s }
end