Class: FileParser
- Inherits:
-
Object
- Object
- FileParser
- Defined in:
- lib/file_parser.rb
Overview
Parses code in a file
Constant Summary collapse
- RUNNABLE_TAG =
:runnable
Instance Attribute Summary collapse
-
#all_objects ⇒ Object
readonly
array of #YARD::CodeObjects.
Class Method Summary collapse
-
.select_option_tags(yard_object) ⇒ Array(YARD::Tags::Tag)
Select all @option tags from of specified object.
-
.select_param_tags(yard_object) ⇒ Array(YARD::Tags::Tag)
Select all @param tags from of specified object.
-
.select_runnable_tags(yard_object) ⇒ Array(YARD::Tags::Tag)
Select all @runnable tags from of specified object.
Instance Method Summary collapse
-
#initialize(file_path) ⇒ FileParser
constructor
Parse file with #YARD::CLI::Stats.
-
#list_classes(scope = :all) ⇒ Array(YARD::CodeObjects::ClassObject)
List classes.
-
#list_methods(scope = :all, clazz = nil) ⇒ Array(YARD::CodeObjects::MethodObject)
List of methods.
Constructor Details
#initialize(file_path) ⇒ FileParser
Parse file with #YARD::CLI::Stats
14 15 16 17 18 19 |
# File 'lib/file_parser.rb', line 14 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 end |
Instance Attribute Details
#all_objects ⇒ Object (readonly)
array of #YARD::CodeObjects
9 10 11 |
# File 'lib/file_parser.rb', line 9 def all_objects @all_objects end |
Class Method Details
.select_option_tags(yard_object) ⇒ Array(YARD::Tags::Tag)
Select all @option tags from of specified object
76 77 78 |
# File 'lib/file_parser.rb', line 76 def self.(yard_object) yard_object..select { |t| t.tag_name == 'option' } end |
.select_param_tags(yard_object) ⇒ Array(YARD::Tags::Tag)
Select all @param tags from of specified object
84 85 86 |
# File 'lib/file_parser.rb', line 84 def self.(yard_object) yard_object..select { |t| t.tag_name == 'param' } end |
.select_runnable_tags(yard_object) ⇒ Array(YARD::Tags::Tag)
Select all @runnable tags from of specified object
68 69 70 |
# File 'lib/file_parser.rb', line 68 def self.(yard_object) yard_object..select { |t| t.tag_name == RUNNABLE_TAG.to_s } end |
Instance Method Details
#list_classes(scope = :all) ⇒ Array(YARD::CodeObjects::ClassObject)
List classes
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/file_parser.rb', line 52 def list_classes(scope= :all) all_classes = @all_objects.select { |o| o.type == :class } case scope when :all all_classes when RUNNABLE_TAG all_classes.select { |m| m.has_tag? RUNNABLE_TAG } else raise ":scope can be :all or #{RUNNABLE_TAG}" end end |
#list_methods(scope = :all, clazz = nil) ⇒ Array(YARD::CodeObjects::MethodObject)
List of methods
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/file_parser.rb', line 25 def list_methods(scope = :all, clazz = nil) all_methods = @all_objects.select { |o| o.type == :method } all_class_methods = [] all_class_methods = clazz.children.select { |m| m.class == YARD::CodeObjects::MethodObject } if clazz case scope when :all if clazz all_class_methods else all_methods end when RUNNABLE_TAG if clazz all_class_methods.select { |m| m.has_tag? RUNNABLE_TAG } else all_methods.select { |m| m.has_tag? RUNNABLE_TAG } end else raise ":scope can be :all or #{RUNNABLE_TAG}" end end |