class YARD::Handlers::Chef::ResourcePropertyHandler

Handles properties in custom resources and LWRPs

Public Instance Methods

parse_option_list(list) click to toggle source

Goes through the option list AST node and returns a simple hash

@return [Hash] The options passed as a hash

# File lib/yard-chefdoc/handlers/resource_property.rb, line 42
def parse_option_list(list)
  return nil if list.nil? || list.empty?
  opts = {}
  list.each do |opt|
    next unless opt.type == :assoc
    opts[opt[0].source.delete(':')] = opt[1].source
  end

  opts
end
process() click to toggle source
# File lib/yard-chefdoc/handlers/resource_property.rb, line 10
def process
  resource_obj = ChefObject.register(filename, :resource, statement.file)

  docstring_is_header = (statement.docstring == resource_obj.header)
  resource_obj.add_property res_prop_hash(docstring_is_header)
end
res_prop_hash(nodoc) click to toggle source

Creates the hash to initialize the single resource property object

@return [Hash] the hash to initialize the property in the resource code object

# File lib/yard-chefdoc/handlers/resource_property.rb, line 21
def res_prop_hash(nodoc)
  props = {}
  statement[1].entries.each do |e|
    next if e == false
    if %i[var_ref array].include?(e.type)
      props[:type] = e.source
    elsif e.type == :symbol_literal
      props[:identifier] = e.source.delete(':')
    elsif e.type == :list
      props[:options] = parse_option_list(e)
    end
  end
  props[:docstring] = nodoc ? '' : statement.docstring

  props
end