class YARD::Handlers::Chef::RecipeHandler
Handles “recipes” in a cookbook.
Public Instance Methods
name()
click to toggle source
Gets the recipe name from the metadata.rb.
@return [String] the recipe name
# File lib/yard-chef/handlers/recipe.rb, line 61 def name recipe = statement.parameters.first.jump(:string_content, :ident).source recipe = recipe.split('::')[1] if recipe =~ /::/ recipe = 'default' if recipe == cookbook.name.to_s recipe end
parse_docs()
click to toggle source
Gets the docstring for the recipe. The docstring is obtained from the description field in the recipe.
@return [YARD::Docsting] the docstring
# File lib/yard-chef/handlers/recipe.rb, line 73 def parse_docs; end
process()
click to toggle source
# File lib/yard-chef/handlers/recipe.rb, line 31 def process path_array = statement.file.to_s.split('/') # Recipe declaration in metadata.rb if path_array.include?('metadata.rb') && (statement.jump(:ident).source == 'recipe') description = '' recipe_obj = ChefObject.register(cookbook, name, :recipe) # YARD builds an abstract syntax tree (AST) which we need to traverse # to obtain the complete docstring statement.parameters[1].traverse do |child| description << child.jump(:string_content).source if child.type == :string_content end recipe_obj.short_desc = YARD::DocstringParser.new.parse(description).to_docstring recipe_obj.docstring = statement.docstring end # Recipe description in the head of recipe, leading comment block if path_array.include? 'recipes' recipe_obj = ChefObject.register(cookbook, ::File.basename(statement.file.to_s, '.rb'), :recipe) if statement.docstring =~ /[\s\t]*\*?Description[:]?\*?/i recipe_obj.docstring = statement.docstring end end recipe_obj end