Class: YARD::Handlers::Chef::AttributeHandler
- Defined in:
- lib/yard-chef/handlers/attribute.rb
Overview
Handles “attributes” in cookbook metadata and lightweight resource.
Instance Method Summary collapse
-
#docstring ⇒ YARD::Docstring
Get the docstring related to the attributes.
-
#process ⇒ Object
Process “attribute” keyword.
Methods inherited from Base
Instance Method Details
#docstring ⇒ YARD::Docstring
Get the docstring related to the attributes. The docstring is obtained from the “:description” field in the attribute.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/yard-chef/handlers/attribute.rb', line 60 def docstring description = "" path_array = parser.file.to_s.split('/') if path_array.include?('metadata.rb') # Suppose :description string have concatenation operator '+' then # YARD builds an abstract syntax tree (AST). We need to traverse the # tree to get the whole description string statement.parameters[1].children.each do |ast_node| if ast_node.jump(:ident).source == "description" ast_node.traverse do |child| description << child.jump(:string_content).source if child.type == :string_content end end end else description = statement.comments end YARD::DocstringParser.new.parse(description).to_docstring end |
#process ⇒ Object
Process “attribute” keyword.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/yard-chef/handlers/attribute.rb', line 33 def process # If file path includes metadata then handle cookbook attributes # else handle resource attributes if parser.file =~ /metadata\.rb/ namespace = cookbook else namespace = lwrp namespace.add_file(statement.file) cookbook_obj = cookbook unless cookbook_obj.resources.include?(namespace) cookbook_obj.resources.push(namespace) end end # Register attribute if not already registered attrib_obj = ChefObject.register(namespace, name, :attribute) attrib_obj.source = statement.source attrib_obj.docstring = docstring attrib_obj.add_file(statement.file, statement.line) end |