Class: YARD::Handlers::Chef::RecipeHandler

Inherits:
Base
  • Object
show all
Defined in:
lib/yard-chef/handlers/recipe.rb

Overview

Handles “recipes” in a cookbook.

Instance Method Summary collapse

Methods inherited from Base

#cookbook, #lwrp

Instance Method Details

#docstringYARD::Docsting

Gets the docstring for the recipe. The docstring is obtained from the description field in the recipe.

Returns:

  • (YARD::Docsting)

    the docstring



53
54
55
56
57
58
59
60
61
# 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

#nameString

Gets the recipe name from the metadata.rb.

Returns:

  • (String)

    the recipe name



41
42
43
44
45
46
# 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

#processObject



30
31
32
33
34
35
# 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