Class: YARD::Handlers::Chef::RecipeHandler
- Defined in:
- lib/yard-chef/handlers/recipe.rb
Overview
Handles “recipes” in a cookbook.
Instance Method Summary collapse
-
#name ⇒ String
Gets the recipe name from the metadata.rb.
-
#parse_docs ⇒ YARD::Docsting
Gets the docstring for the recipe.
- #process ⇒ Object
Methods inherited from Base
Instance Method Details
#name ⇒ String
Gets the recipe name from the metadata.rb.
61 62 63 64 65 66 |
# 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 ⇒ YARD::Docsting
Gets the docstring for the recipe. The docstring is obtained from the description field in the recipe.
73 |
# File 'lib/yard-chef/handlers/recipe.rb', line 73 def parse_docs; end |
#process ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# 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 |