class YARD::Handlers::Chef::RecipeHandler

Handles “recipes” in a cookbook.

Public Instance Methods

docstring() 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 53
def docstring
  description = ""
  # 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
  YARD::DocstringParser.new.parse(description).to_docstring
end
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 41
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
process() click to toggle source
# File lib/yard-chef/handlers/recipe.rb, line 30
def process
  return unless statement.file.to_s =~ /metadata.rb/

  recipe_obj = ChefObject.register(cookbook, name, :recipe)
  recipe_obj.docstring = docstring
end