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 86 def docstring(base_dir) type = '' string = '' readme_path = base_dir + '/README.md' if File.exist?(readme_path) type = :markdown string = IO.read(readme_path) else readme_path = base_dir + '/README.rdoc' if File.exist?(readme_path) type = :rdoc string = IO.read(readme_path) end end [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 = '' value = statement.parameters.first if value.is_a?(YARD::Parser::Ruby::MethodCallNode) # The content is code, so evaluate it in the correct directory # This handles ruby code like File.read in metadata.rb current_directory = Dir.getwd Dir.chdir(File.expand_path(File.dirname(statement.file))) string << eval(value.source) Dir.chdir current_directory else # YARD builds an abstract syntax tree (AST) which we need to traverse # to obtain the complete docstring value.traverse do |child| string << child.jump(:string_content).source if child.type == :string_content end 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