Class: YARD::Handlers::Chef::Base

Inherits:
Ruby::Base
  • Object
show all
Includes:
CodeObjects::Chef
Defined in:
lib/yard-chef/handlers/base.rb

Overview

Base handler for chef elements.

Instance Method Summary collapse

Instance Method Details

#cookbookCookbookObject

Registers the cookbook in Registry and returns the same.

Returns:

  • (CookbookObject)

    the CookbookObject



41
42
43
44
45
46
47
48
49
50
# File 'lib/yard-chef/handlers/base.rb', line 41

def cookbook
  cookbook_name = ''
  path_array = File.expand_path(statement.file).to_s.split('/')
  cookbook_name = if path_array.include?('metadata.rb')
                    path_array[path_array.index('metadata.rb') - 1]
                  else
                    path_array[path_array.length - 3]
                  end
  ChefObject.register(CHEF, cookbook_name, :cookbook)
end

#lwrpResourceObject or ProviderObject

Registers the lightweight resource and provider in YARD::Registry and returns the same.

provider

Returns:

  • (ResourceObject or ProviderObject)

    the lightweight resource or



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/yard-chef/handlers/base.rb', line 58

def lwrp
  path_array = File.expand_path(statement.file).to_s.split('/')
  if path_array.include?('resources')
    type = RESOURCE
    type_sym = :resource
  elsif path_array.include?('providers')
    type = PROVIDER
    type_sym = :provider
  else
    raise "Invalid LWRP type #{@path_array.join(',')}"
  end
  file_name = path_array.last.to_s.sub('.rb', '')

  cookbook_obj = cookbook
  lwrp_name = if file_name == 'default'
                cookbook_obj.name
              else
                "#{cookbook_obj.name}_#{file_name}"
              end
  ChefObject.register(type, lwrp_name, type_sym)
end

#nameObject

Gets the name of the handled object.



33
34
35
# File 'lib/yard-chef/handlers/base.rb', line 33

def name
  statement.parameters.first.jump(:string_content, :ident).source
end