-
-
Notifications
You must be signed in to change notification settings - Fork 397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extracting tag information from files #1076
Comments
Thanks for you question, and I'm also interested in something like this. I'm going to place links to functional requirements in source code comments by custom tag, and then do some traceability automation, by extracting source code items related to requirements ... just all source code items where exists @requirement tag. Something like this # @requirement fr.foo
class Foo
# @requirement fr.foo.bar
def bar
end
end Can I get something next? [{file: 'foo.rb', class: 'Foo'}, {file: 'foo.rb', meth: 'Foo#bar'}] |
Sorry for the delay on getting to this. YARD has an extensive programmatic API that lets you do a lot of code auditing. Check out the Architecture Overview for some high level docs that drill down into what you may need. Generally you'll want to look at the Registry, CodeObjects, and tags. The short example is: require 'yard'
# Equivalent to running `yard -n` before this script
YARD::CLI::Yardoc.run('-n')
# Load the registry that was written by above command
YARD::Registry.load
# Get all the method objects
meths = YARD::Registry.all(:method)
p meths
# Get all the objects with only 1 @return tag
objs = YARD::Registry.all.select do |obj|
obj.has_tag?(:return) && obj.tags(:return).size == 1
end
# Get all objects defined in foo.rb
objs = YARD::Registry.all.select do |obj|
obj.files.include? 'foo.rb'
end Hope that helps! |
@isegal I am wondering how do you print the return types in the code above? |
@EricaZhang17 you can see the tags documentation linked above or see Docstring#tags but basically the |
I am wondering if it is possible to render the tag information so that it for each method, there can be a list of information like ClassName, MethodName, "(Param1Type, Param2Type, ...) -> ReturnType" ? Right now using p obj.tags(:param) or p obj.tags(:return), I am able to get a list of objects [#<YARD::Tags::Tag:0x007fea390943b0 @tag_name="param", @text="an Object to compare this {Country} with.", @name="c", @types=["Object"], @object=#<yardoc method TZInfo::Country#eql?>>] but I can't seem to combine the two type information together. Thank you!@isegal |
I am trying to parse through each file and get the @tag value.
Example
If I want to retrieve to retrieve @return from yard documentation. What would be the best way to do it.
Thanks :)
The text was updated successfully, but these errors were encountered: