YARD::Handlers::Chef::AttributeHandler

Handles “attributes” in cookbook metadata and lightweight resource.

Public Instance Methods

docstring() click to toggle source

Get the docstring related to the attributes. The docstring is obtained from the “:description” field in the attribute.

@return [YARD::Docstring] docstring for the attribute

# 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() click to toggle source

Process “attribute” keyword.

# 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

[Validate]

Generated with the Darkfish Rdoc Generator 2.