class YARD::Handlers::Chef::CookbookHandler
Handles specific cookbook information like README, description and version.
Public Instance Methods
docstring(base_dir)
click to toggle source
Generates docstring from the README file.
@return [YARD::Docstring] the docstring
# File lib/yard-chef/handlers/cookbook.rb, line 76 def docstring(base_dir) type = '' string = '' readme_path = base_dir + '/README.md' if File.exists?(readme_path) type = :markdown string = IO.read(readme_path) else readme_path = base_dir + '/README.rdoc' if File.exists?(readme_path) type = :rdoc string = IO.read(readme_path) end end return YARD::DocstringParser.new.parse(string).to_docstring, type end
name()
click to toggle source
Get the name of the method being handled.
@return [String] the method name
# File lib/yard-chef/handlers/cookbook.rb, line 62 def name string = "" # YARD builds an abstract syntax tree (AST) which we need to traverse # to obtain the complete docstring statement.parameters.first.traverse do |child| string << child.jump(:string_content).source if child.type == :string_content end string end
process()
click to toggle source
# File lib/yard-chef/handlers/cookbook.rb, line 32 def process return unless statement.file.to_s =~ /metadata.rb/ # Register the cookbook cookbook_obj = cookbook cookbook_obj.add_file(statement.file) case statement.first.source when 'description' cookbook_obj.short_desc = name when 'version' cookbook_obj.version = name end # Get the README file for the cookbook base_dir = File.dirname(statement.file) if cookbook_obj.docstring == '' cookbook_obj.docstring, cookbook_obj.docstring_type = docstring(base_dir) end # Get the top-level README for the cookbook repository if it exists if CHEF.docstring == '' readme_dir = File.expand_path('../..', base_dir) CHEF.docstring, CHEF.docstring_type = docstring(readme_dir) end end