Class: YARD::CodeObjects::Chef::ChefObject

Inherits:
YARD::CodeObjects::ClassObject
  • Object
show all
Defined in:
lib/yard-chef/code_objects/chef_object.rb

Overview

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(namespace, name) ⇒ ChefObject

Creates a new ChefObject object.

Parameters:

  • namespace (NamespaceObject)

    namespace to which the object belongs

  • name (String)

    name of the ChefObject



43
44
45
46
# File 'lib/yard-chef/code_objects/chef_object.rb', line 43

def initialize(namespace, name)
  super(namespace, name)
  @docstring_type = :markdown
end

Instance Attribute Details

#docstring_typeSymbol, String (readonly)

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

Returns:

  • (Symbol, String)

    formatting type



34
35
36
# File 'lib/yard-chef/code_objects/chef_object.rb', line 34

def docstring_type
  @docstring_type
end

Class Method Details

.register(namespace, name, type) ⇒ <type>Object

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

belong

Parameters:

  • namespace (NamespaceObject)

    namespace to which the object must

  • name (String)

    name of the chef element

  • type (Symbol, String)

    type of the chef element

Returns:

  • (<type>Object)

    the element object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
# 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) ⇒ Object

Register a chef element class.

Parameters:

  • element (Class)

    chef element class



52
53
54
55
# File 'lib/yard-chef/code_objects/chef_object.rb', line 52

def self.register_element(element)
  @@chef_elements ||= {}
  @@chef_elements[element] = self
end

Instance Method Details

#children_by_type(type) ⇒ Array<ChefObject>

Returns children of an object of a particular type.

Parameters:

  • type (Symbol)

    type of ChefObject to be selected

Returns:



88
89
90
91
# File 'lib/yard-chef/code_objects/chef_object.rb', line 88

def children_by_type(type)
  children = YARD::Registry.all(type)
  children.select { |child| child.parent == self }
end

#cookbooksArray<CookbookObject>

Gets all Chef cookbooks.

Returns:



97
98
99
# File 'lib/yard-chef/code_objects/chef_object.rb', line 97

def cookbooks
  children_by_type(:cookbook)
end