Class: YARD::CodeObjects::Chef::ProviderObject

Inherits:
ChefObject
  • Object
show all
Defined in:
lib/yard-chef/code_objects/provider_object.rb

Overview

A ProviderObject represents a lightweight provider in Chef. See docs.opscode.com/essentials_cookbook_lwrp.html

Instance Attribute Summary

Attributes inherited from ChefObject

#docstring_type

Instance Method Summary collapse

Methods inherited from ChefObject

#children_by_type, #cookbooks, register, register_element

Constructor Details

#initialize(namespace, name) ⇒ ProviderObject

Creates a new instance of ProviderObject.

provider belongs

Parameters:

  • namespace (NamespaceObject)

    namespace to which the lightweight

  • name (String)

    name of the lightweight provider



40
41
42
43
# File 'lib/yard-chef/code_objects/provider_object.rb', line 40

def initialize(namespace, name)
  super(namespace, name)
  @description = ''
end

Instance Method Details

#actionsArray<ActionObject>

Actions implemented in the lightweight provider.

Returns:



81
82
83
# File 'lib/yard-chef/code_objects/provider_object.rb', line 81

def actions
  children_by_type(:action)
end

#long_nameString

Constructs class name for the lightweight provider.

Returns:

  • (String)

    the class name for the lightweight provider



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/yard-chef/code_objects/provider_object.rb', line 49

def long_name
  name = ''
  if @name.to_s =~ /_/
    @name.to_s.split('_').each do |str|
      name << str.to_s.capitalize
    end
  else
    name = @name.to_s.capitalize
  end
  namespace = @namespace.to_s.split('::').map(&:capitalize)
  "#{namespace.join('::')}::#{name}"
end

#map_resource(file) ⇒ Object

Maps provider with a lightweight resource.

Parameters:

  • path (String)

    to the lightweight provider file.



66
67
68
69
70
71
72
73
74
75
# File 'lib/yard-chef/code_objects/provider_object.rb', line 66

def map_resource(file)
  file_handle = File.open(File.expand_path(file), 'r')
  file_handle.readlines.each do |line|
    next unless line =~ /#\s@resource/
    resource_name = line.split(/@resource /)[1].strip
    @resource = ChefObject.register(RESOURCE, resource_name, :resource)
    @resource.providers.push(self) unless @resource.providers.include?(self)
    break
  end
end