class YARD::CodeObjects::Chef::ChefObject

A ChefObject is an abstract implementation of all chef elements (cookbooks, resources, providers, recipes, attributes and actions).

Attributes

docstring_type[R]

Returns the formatting type of docstring (Example: :markdown, :rdoc).

@return [Symbol, String] formatting type

Public Class Methods

new(namespace, name) click to toggle source

Creates a new ChefObject object.

@param namespace [NamespaceObject] namespace to which the object belongs @param name [String] name of the ChefObject

@return [ChefObject] the newly created ChefObject

Calls superclass method
# File lib/yard-chef/code_objects/chef_object.rb, line 43
def initialize(namespace, name)
  super(namespace, name)
  @docstring_type = :markdown
end
register(namespace, name, type) click to toggle source

Factory for creating and registering chef element object in YARD::Registry.

@param namespace [NamespaceObject] namespace to which the object must belong @param name [String] name of the chef element @param type [Symbol, String] type of the chef element

@return [<type>Object] the element object

# File lib/yard-chef/code_objects/chef_object.rb, line 67
def self.register(namespace, name, type)
  element = @@chef_elements[type]
  if element
    element_obj = YARD::Registry.resolve(:root, "#{namespace}::#{name}")
    if element_obj.nil?
      element_obj = element.new(namespace, name)
      log.info "Created [#{type.to_s.capitalize}]" +
        " #{element_obj.name} => #{element_obj.namespace}"
    end
    element_obj
  else
    raise "Invalid chef element type #{type}"
  end
end
register_element(element) click to toggle source

Register a chef element class.

@param element [Class] chef element class

# File lib/yard-chef/code_objects/chef_object.rb, line 52
def self.register_element(element)
  @@chef_elements ||= {}
  @@chef_elements[element] = self
end

Public Instance Methods

children_by_type(type) click to toggle source

Returns children of an object of a particular type.

@param type [Symbol] type of ChefObject to be selected

@return [Array<ChefObject>] list of ChefObjects

# File lib/yard-chef/code_objects/chef_object.rb, line 88
def children_by_type(type)
  children = YARD::Registry.all(type)
  children.reject { |child| child.parent != self }
end
cookbooks() click to toggle source

Gets all Chef cookbooks.

@return [Array<CookbookObject>] list of cookbooks.

# File lib/yard-chef/code_objects/chef_object.rb, line 97
def cookbooks
  children_by_type(:cookbook)
end