yard-chef 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/yard-chef.rb +74 -0
- data/lib/yard-chef/code_objects/action_object.rb +43 -0
- data/lib/yard-chef/code_objects/attribute_object.rb +45 -0
- data/lib/yard-chef/code_objects/chef_object.rb +107 -0
- data/lib/yard-chef/code_objects/cookbook_object.rb +109 -0
- data/lib/yard-chef/code_objects/provider_object.rb +89 -0
- data/lib/yard-chef/code_objects/recipe_object.rb +52 -0
- data/lib/yard-chef/code_objects/resource_object.rb +83 -0
- data/lib/yard-chef/handlers/action.rb +52 -0
- data/lib/yard-chef/handlers/actions.rb +57 -0
- data/lib/yard-chef/handlers/attribute.rb +81 -0
- data/lib/yard-chef/handlers/base.rb +81 -0
- data/lib/yard-chef/handlers/cookbook.rb +94 -0
- data/lib/yard-chef/handlers/define.rb +40 -0
- data/lib/yard-chef/handlers/recipe.rb +64 -0
- data/templates/default/action/html/action_list.erb +42 -0
- data/templates/default/action/html/action_summary.erb +37 -0
- data/templates/default/action/html/setup.rb +36 -0
- data/templates/default/action/html/source.erb +34 -0
- data/templates/default/attribute/html/attribute_header.erb +28 -0
- data/templates/default/attribute/html/setup.rb +26 -0
- data/templates/default/attribute/html/table.erb +40 -0
- data/templates/default/chef/html/cookbook_table.erb +45 -0
- data/templates/default/chef/html/docstring.erb +25 -0
- data/templates/default/chef/html/setup.rb +26 -0
- data/templates/default/cookbook/html/cookbook_title.erb +28 -0
- data/templates/default/cookbook/html/definitions.erb +38 -0
- data/templates/default/cookbook/html/docstring.erb +25 -0
- data/templates/default/cookbook/html/element_details.erb +27 -0
- data/templates/default/cookbook/html/generated_docs.erb +26 -0
- data/templates/default/cookbook/html/libraries.erb +35 -0
- data/templates/default/cookbook/html/recipes.erb +38 -0
- data/templates/default/cookbook/html/setup.rb +40 -0
- data/templates/default/definition/html/definition_list.erb +36 -0
- data/templates/default/definition/html/setup.rb +29 -0
- data/templates/default/definition/html/source.erb +34 -0
- data/templates/default/fulldoc/html/css/common.css +15 -0
- data/templates/default/fulldoc/html/full_list_cookbooks.erb +35 -0
- data/templates/default/fulldoc/html/full_list_definitions.erb +37 -0
- data/templates/default/fulldoc/html/full_list_recipes.erb +37 -0
- data/templates/default/fulldoc/html/full_list_resources.erb +39 -0
- data/templates/default/fulldoc/html/setup.rb +99 -0
- data/templates/default/layout/html/cookbook_table.erb +46 -0
- data/templates/default/layout/html/setup.rb +58 -0
- data/templates/default/layout/html/title.erb +28 -0
- data/templates/default/provider/html/providers_summary.erb +31 -0
- data/templates/default/provider/html/setup.rb +26 -0
- data/templates/default/recipe/html/recipe_list.erb +37 -0
- data/templates/default/recipe/html/setup.rb +29 -0
- data/templates/default/recipe/html/source.erb +34 -0
- data/templates/default/resource/html/actions.erb +43 -0
- data/templates/default/resource/html/providers_list.erb +38 -0
- data/templates/default/resource/html/resource_list.erb +31 -0
- data/templates/default/resource/html/setup.rb +37 -0
- metadata +137 -0
data/lib/yard-chef.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Copyright (c) 2012 RightScale, Inc.
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# 'Software'), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
17
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
18
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
19
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
20
|
+
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
require 'yard'
|
23
|
+
|
24
|
+
require 'yard-chef/code_objects/chef_object'
|
25
|
+
require 'yard-chef/code_objects/cookbook_object'
|
26
|
+
require 'yard-chef/code_objects/resource_object'
|
27
|
+
require 'yard-chef/code_objects/provider_object'
|
28
|
+
require 'yard-chef/code_objects/recipe_object'
|
29
|
+
require 'yard-chef/code_objects/attribute_object'
|
30
|
+
require 'yard-chef/code_objects/action_object'
|
31
|
+
|
32
|
+
require 'yard-chef/handlers/base'
|
33
|
+
require 'yard-chef/handlers/action'
|
34
|
+
require 'yard-chef/handlers/attribute'
|
35
|
+
require 'yard-chef/handlers/define'
|
36
|
+
require 'yard-chef/handlers/actions'
|
37
|
+
require 'yard-chef/handlers/cookbook'
|
38
|
+
require 'yard-chef/handlers/recipe'
|
39
|
+
|
40
|
+
module YARD::CodeObjects::Chef
|
41
|
+
# Since 'recipe' files do not have a specific keyword that can be matched,
|
42
|
+
# iterate through the list of files to be parsed and register the recipes.
|
43
|
+
# Description for every recipe may be found in 'metadata.rb' which can
|
44
|
+
# be taken care of in the handler.
|
45
|
+
# TODO: Investigate if YARD handlers can be invoked if parser is in a
|
46
|
+
# specific directory.
|
47
|
+
YARD::Parser::SourceParser.before_parse_list do |files, globals|
|
48
|
+
files.each do |file|
|
49
|
+
path_arr = File.expand_path(file).to_s.split('/')
|
50
|
+
unless (index = path_arr.index('recipes')).nil?
|
51
|
+
# Cookbook name can be derived from file path
|
52
|
+
# cookbook/<cookbook_name>/recipes/recipe_name.rb
|
53
|
+
cookbook_name = path_arr[index - 1]
|
54
|
+
cookbook = ChefObject.register(CHEF, cookbook_name, :cookbook)
|
55
|
+
|
56
|
+
recipe_name = path_arr.last.to_s.sub('.rb','')
|
57
|
+
recipe = ChefObject.register(cookbook, recipe_name, :recipe)
|
58
|
+
|
59
|
+
recipe.source = IO.read(file)
|
60
|
+
recipe.add_file(file, 1)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# Register '@resource' tag for mapping providers with light-weight resources
|
66
|
+
YARD::Tags::Library.define_tag(
|
67
|
+
'Map Chef Providers with Chef Resources',
|
68
|
+
:resource
|
69
|
+
)
|
70
|
+
|
71
|
+
# Register template directory for the chef plugin
|
72
|
+
template_dir = File.expand_path('../templates', File.dirname(__FILE__))
|
73
|
+
YARD::Templates::Engine.register_template_path(template_dir.to_s)
|
74
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# Copyright (c) 2012 RightScale, Inc.
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# 'Software'), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
17
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
18
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
19
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
20
|
+
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
require 'yard'
|
23
|
+
|
24
|
+
module YARD::CodeObjects
|
25
|
+
module Chef
|
26
|
+
# An ActionObject represents an action in a lightweight provider.
|
27
|
+
# See http://wiki.opscode.com/display/chef/Lightweight+Resources+and+Providers+%28LWRP%29#LightweightResourcesandProviders%28LWRP%29-Keyword%3Aaction
|
28
|
+
#
|
29
|
+
class ActionObject < ChefObject
|
30
|
+
register_element :action
|
31
|
+
|
32
|
+
# Creates a new instance of the ActionObject
|
33
|
+
#
|
34
|
+
# @param namespace [NamespaceObject] namespace to which the action belongs
|
35
|
+
# @param name [String] name of the action
|
36
|
+
#
|
37
|
+
# @return [ActionObject] the newly created ActionObject
|
38
|
+
def initialize(namespace, name)
|
39
|
+
super(namespace, name)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# Copyright (c) 2012 RightScale, Inc.
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# 'Software'), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
17
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
18
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
19
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
20
|
+
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
require 'yard'
|
23
|
+
|
24
|
+
module YARD::CodeObjects
|
25
|
+
module Chef
|
26
|
+
# An AttributeObject represents a cookbook or a resource attribute.
|
27
|
+
# See http://wiki.opscode.com/display/chef/Attributes
|
28
|
+
#
|
29
|
+
class AttributeObject < ChefObject
|
30
|
+
register_element :attribute
|
31
|
+
|
32
|
+
# Creates a new instance of the AttributeObject.
|
33
|
+
#
|
34
|
+
# @param namespace [NamespaceObject] namespace to which the attribute
|
35
|
+
# belongs
|
36
|
+
# @param name [String] name of the attribute
|
37
|
+
#
|
38
|
+
# @return [AttributeObject] the newly created AttribteObject
|
39
|
+
#
|
40
|
+
def initialize(namespace, name)
|
41
|
+
super(namespace, name)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# Copyright (c) 2012 RightScale, Inc.
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# 'Software'), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
17
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
18
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
19
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
20
|
+
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
require 'yard'
|
23
|
+
|
24
|
+
module YARD::CodeObjects
|
25
|
+
module Chef
|
26
|
+
# A ChefObject is an abstract implementation of all chef elements
|
27
|
+
# (cookbooks, resources, providers, recipes, attributes and actions).
|
28
|
+
#
|
29
|
+
class ChefObject < YARD::CodeObjects::ClassObject
|
30
|
+
# Returns the formatting type of docstring (Example: :markdown, :rdoc).
|
31
|
+
#
|
32
|
+
# @return [Symbol, String] formatting type
|
33
|
+
#
|
34
|
+
attr_reader :docstring_type
|
35
|
+
|
36
|
+
# Creates a new ChefObject object.
|
37
|
+
#
|
38
|
+
# @param namespace [NamespaceObject] namespace to which the object belongs
|
39
|
+
# @param name [String] name of the ChefObject
|
40
|
+
#
|
41
|
+
# @return [ChefObject] the newly created ChefObject
|
42
|
+
#
|
43
|
+
def initialize(namespace, name)
|
44
|
+
super(namespace, name)
|
45
|
+
@docstring_type = :markdown
|
46
|
+
end
|
47
|
+
|
48
|
+
# Register a chef element class.
|
49
|
+
#
|
50
|
+
# @param element [Class] chef element class
|
51
|
+
#
|
52
|
+
def self.register_element(element)
|
53
|
+
@@chef_elements ||= {}
|
54
|
+
@@chef_elements[element] = self
|
55
|
+
end
|
56
|
+
|
57
|
+
# Factory for creating and registering chef element object in
|
58
|
+
# YARD::Registry.
|
59
|
+
#
|
60
|
+
# @param namespace [NamespaceObject] namespace to which the object must
|
61
|
+
# belong
|
62
|
+
# @param name [String] name of the chef element
|
63
|
+
# @param type [Symbol, String] type of the chef element
|
64
|
+
#
|
65
|
+
# @return [<type>Object] the element object
|
66
|
+
#
|
67
|
+
def self.register(namespace, name, type)
|
68
|
+
element = @@chef_elements[type]
|
69
|
+
if element
|
70
|
+
element_obj = YARD::Registry.resolve(:root, "#{namespace}::#{name}")
|
71
|
+
if element_obj.nil?
|
72
|
+
element_obj = element.new(namespace, name)
|
73
|
+
log.info "Created [#{type.to_s.capitalize}]" +
|
74
|
+
" #{element_obj.name} => #{element_obj.namespace}"
|
75
|
+
end
|
76
|
+
element_obj
|
77
|
+
else
|
78
|
+
raise "Invalid chef element type #{type}"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# Returns children of an object of a particular type.
|
83
|
+
#
|
84
|
+
# @param type [Symbol] type of ChefObject to be selected
|
85
|
+
#
|
86
|
+
# @return [Array<ChefObject>] list of ChefObjects
|
87
|
+
#
|
88
|
+
def children_by_type(type)
|
89
|
+
children = YARD::Registry.all(type)
|
90
|
+
children.reject { |child| child.parent != self }
|
91
|
+
end
|
92
|
+
|
93
|
+
# Gets all Chef cookbooks.
|
94
|
+
#
|
95
|
+
# @return [Array<CookbookObject>] list of cookbooks.
|
96
|
+
#
|
97
|
+
def cookbooks
|
98
|
+
children_by_type(:cookbook)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
# Register 'Chef' as the root namespace
|
103
|
+
CHEF = ChefObject.new(:root, 'chef')
|
104
|
+
|
105
|
+
log.info "Creating [Chef] as 'root' namespace"
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# Copyright (c) 2012 RightScale, Inc.
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# 'Software'), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
17
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
18
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
19
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
20
|
+
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
require 'yard'
|
23
|
+
|
24
|
+
module YARD::CodeObjects
|
25
|
+
module Chef
|
26
|
+
# A CookbookObject represents a Chef cookbook.
|
27
|
+
# See http://wiki.opscode.com/display/chef/Cookbooks for more information
|
28
|
+
# about cookbook.
|
29
|
+
#
|
30
|
+
class CookbookObject < ChefObject
|
31
|
+
register_element :cookbook
|
32
|
+
|
33
|
+
# Short description for the cookbook.
|
34
|
+
#
|
35
|
+
# @param short_desc [String] short description for the cookbook
|
36
|
+
#
|
37
|
+
# @return [String] short description for the cookbook
|
38
|
+
#
|
39
|
+
attr_accessor :short_desc
|
40
|
+
|
41
|
+
# Version of the cookbook.
|
42
|
+
#
|
43
|
+
# @param version [String] version for the cookbook
|
44
|
+
#
|
45
|
+
# @return [String] version for the cookbook
|
46
|
+
#
|
47
|
+
attr_accessor :version
|
48
|
+
|
49
|
+
# Lightweight resources implemented in the cookbook.
|
50
|
+
#
|
51
|
+
# @return [Array<ResourceObject>] lightweight resources in the cookbook
|
52
|
+
#
|
53
|
+
attr_reader :resources
|
54
|
+
|
55
|
+
# Lightweight providers implemented in the cookbook.
|
56
|
+
#
|
57
|
+
# @return [Array<ProviderObject>] lightweight providers in the cookbook
|
58
|
+
#
|
59
|
+
attr_reader :providers
|
60
|
+
|
61
|
+
# Creates a new CookbookObject instance.
|
62
|
+
# @param namespace [NamespaceObject] namespace to which the cookbook
|
63
|
+
# belongs
|
64
|
+
# @param name [String] name of the cookbook
|
65
|
+
#
|
66
|
+
# @return [CookbookObject] the newly created CookbookObject
|
67
|
+
#
|
68
|
+
def initialize(namespace, name)
|
69
|
+
super(namespace, name)
|
70
|
+
@resources = []
|
71
|
+
@providers = []
|
72
|
+
@libraries = []
|
73
|
+
end
|
74
|
+
|
75
|
+
# Recipes implemented in the cookbook.
|
76
|
+
#
|
77
|
+
# @return [Array<RecipeObject>] recipes in the cookbook
|
78
|
+
#
|
79
|
+
def recipes
|
80
|
+
children_by_type(:recipe)
|
81
|
+
end
|
82
|
+
|
83
|
+
# Attributes implemented in the cookbook.
|
84
|
+
#
|
85
|
+
# @return [Array<AttributeObject>] attributes in the cookbook
|
86
|
+
#
|
87
|
+
def attributes
|
88
|
+
children_by_type(:attribute)
|
89
|
+
end
|
90
|
+
|
91
|
+
# Definitions implemented in the cookbook.
|
92
|
+
#
|
93
|
+
# @return [Array<MethodObject>] definitions in the cookbook
|
94
|
+
#
|
95
|
+
def definitions
|
96
|
+
children_by_type(:method)
|
97
|
+
end
|
98
|
+
|
99
|
+
# Libraries defined in the cookbook.
|
100
|
+
#
|
101
|
+
# @return [Array<ModuleObject>] libraries in the cookbook
|
102
|
+
#
|
103
|
+
def libraries
|
104
|
+
modules = YARD::Registry.all(:module)
|
105
|
+
modules.select { |lib| !lib.parent.root? && lib.file =~ /#{@name}/ }
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# Copyright (c) 2012 RightScale, Inc.
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# 'Software'), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
17
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
18
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
19
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
20
|
+
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
require 'yard'
|
23
|
+
|
24
|
+
module YARD::CodeObjects
|
25
|
+
module Chef
|
26
|
+
# A ProviderObject represents a lightweight provider in Chef.
|
27
|
+
# See http://docs.opscode.com/essentials_cookbook_lwrp.html
|
28
|
+
#
|
29
|
+
class ProviderObject < ChefObject
|
30
|
+
register_element :provider
|
31
|
+
|
32
|
+
# Creates a new instance of ProviderObject.
|
33
|
+
#
|
34
|
+
# @param namespace [NamespaceObject] namespace to which the lightweight
|
35
|
+
# provider belongs
|
36
|
+
# @param name [String] name of the lightweight provider
|
37
|
+
#
|
38
|
+
# @return [ProviderObject] the newly created ProviderObject
|
39
|
+
#
|
40
|
+
def initialize(namespace, name)
|
41
|
+
super(namespace, name)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Constructs class name for the lightweight provider.
|
45
|
+
#
|
46
|
+
# @return [String] the class name for the lightweight provider
|
47
|
+
#
|
48
|
+
def long_name
|
49
|
+
name = ''
|
50
|
+
if @name.to_s =~ /_/
|
51
|
+
@name.to_s.split('_').each do |str|
|
52
|
+
name << str.to_s.capitalize
|
53
|
+
end
|
54
|
+
else
|
55
|
+
name = @name.to_s.capitalize
|
56
|
+
end
|
57
|
+
namespace = @namespace.to_s.split('::').map { |str| str.capitalize }
|
58
|
+
"#{namespace.join('::')}::#{name}"
|
59
|
+
end
|
60
|
+
|
61
|
+
# Maps provider with a lightweight resource.
|
62
|
+
#
|
63
|
+
# @param [String] path to the lightweight provider file.
|
64
|
+
#
|
65
|
+
def map_resource(file)
|
66
|
+
file_handle = File.open(File.expand_path(file), 'r')
|
67
|
+
file_handle.readlines.each do |line|
|
68
|
+
if line =~ /#\s@resource/
|
69
|
+
resource_name = line.split(%r{@resource })[1].strip
|
70
|
+
@resource = ChefObject.register(RESOURCE, resource_name, :resource)
|
71
|
+
@resource.providers.push(self) unless @resource.providers.include?(self)
|
72
|
+
break
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# Actions implemented in the lightweight provider.
|
78
|
+
#
|
79
|
+
# @return [Array<ActionObject>] actions in the provider
|
80
|
+
#
|
81
|
+
def actions
|
82
|
+
children_by_type(:action)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# Register 'provider' as a child of 'chef' namespace
|
87
|
+
PROVIDER = ChefObject.register(CHEF, 'provider', :provider)
|
88
|
+
end
|
89
|
+
end
|