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
@@ -0,0 +1,52 @@
|
|
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 RecipeObject represents a recipe in a chef cookbook.
|
27
|
+
# See http://docs.opscode.com/essentials_cookbook_recipes.html
|
28
|
+
#
|
29
|
+
class RecipeObject < ChefObject
|
30
|
+
register_element :recipe
|
31
|
+
|
32
|
+
# Creates a new instance of RecipeObject.
|
33
|
+
#
|
34
|
+
# @param namespace [NamespaceObject] namespace to which the recipe belongs
|
35
|
+
# @param name [String] name of the recipe
|
36
|
+
#
|
37
|
+
# @return [RecipeObject] the newly created RecipeObject
|
38
|
+
#
|
39
|
+
def initialize(namespace, name)
|
40
|
+
super(namespace, name)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Prefixes recipe name with the name of the cookbook.
|
44
|
+
#
|
45
|
+
# @return [String] recipe name
|
46
|
+
#
|
47
|
+
def name
|
48
|
+
self.parent.name.to_s << '::' << @name.to_s
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,83 @@
|
|
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 ResourceObject represents a lightweight resource in chef.
|
27
|
+
# See http://docs.opscode.com/essentials_cookbook_lwrp.html
|
28
|
+
#
|
29
|
+
class ResourceObject < ChefObject
|
30
|
+
register_element :resource
|
31
|
+
|
32
|
+
# Creates a new instance of ResourceObject.
|
33
|
+
#
|
34
|
+
# @param namespace [NamespaceObject] namespace to which the lightweight
|
35
|
+
# resource belongs
|
36
|
+
# @param name [String] name of the lightweight resource
|
37
|
+
#
|
38
|
+
# @return [ResourceObject] the newly created ResourceObject
|
39
|
+
#
|
40
|
+
def initialize(namespace, name)
|
41
|
+
super(namespace, name)
|
42
|
+
@providers = []
|
43
|
+
end
|
44
|
+
|
45
|
+
# Constructs class name for the lightweight resource.
|
46
|
+
#
|
47
|
+
# @return [String] class name for the lightweight resource
|
48
|
+
#
|
49
|
+
def long_name
|
50
|
+
name = ''
|
51
|
+
if @name.to_s =~ /_/
|
52
|
+
@name.to_s.split('_').each do |str|
|
53
|
+
name << str.to_s.capitalize
|
54
|
+
end
|
55
|
+
else
|
56
|
+
name = @name.to_s.capitalize
|
57
|
+
end
|
58
|
+
|
59
|
+
namespace = @namespace.to_s.split('::').map { |str| str.capitalize }
|
60
|
+
"#{namespace.join('::')}::#{name}"
|
61
|
+
end
|
62
|
+
|
63
|
+
# Attributes defined in the lightweight resource.
|
64
|
+
#
|
65
|
+
# @return [Array<AttributeObject>] attributes in the lightweight resource
|
66
|
+
#
|
67
|
+
def attributes
|
68
|
+
children_by_type(:attribute)
|
69
|
+
end
|
70
|
+
|
71
|
+
# Actions supported by the lightweight resource.
|
72
|
+
#
|
73
|
+
# @return [Array<ActionObject>] actions in the lightweight resource
|
74
|
+
#
|
75
|
+
def actions
|
76
|
+
children_by_type(:action)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Register 'resource' as a child of 'chef' namespace
|
81
|
+
RESOURCE = ChefObject.register(CHEF, 'resource', :resource)
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,52 @@
|
|
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::Handlers
|
25
|
+
module Chef
|
26
|
+
# Handles "action" in a provider.
|
27
|
+
#
|
28
|
+
class ActionHandler < Base
|
29
|
+
handles method_call(:action)
|
30
|
+
|
31
|
+
def process
|
32
|
+
# Register the provider object
|
33
|
+
provider_obj = lwrp
|
34
|
+
provider_obj.map_resource(statement.file)
|
35
|
+
provider_obj.add_file(statement.file)
|
36
|
+
|
37
|
+
# Add provider to the cookbook to which it belongs
|
38
|
+
cookbook_obj = cookbook
|
39
|
+
unless cookbook_obj.providers.include?(provider_obj)
|
40
|
+
cookbook_obj.providers.push(provider_obj)
|
41
|
+
end
|
42
|
+
provider_obj.cookbook = cookbook_obj
|
43
|
+
|
44
|
+
# Register the action in the provider
|
45
|
+
action_obj = ChefObject.register(provider_obj, name, :action)
|
46
|
+
action_obj.source = statement.source
|
47
|
+
action_obj.docstring = statement.docstring
|
48
|
+
action_obj.add_file(statement.file, statement.line)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,57 @@
|
|
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::Handlers
|
25
|
+
module Chef
|
26
|
+
# Handles list of actions in a lightweight resource.
|
27
|
+
#
|
28
|
+
class ActionsHandler < Base
|
29
|
+
handles method_call(:actions)
|
30
|
+
|
31
|
+
def process
|
32
|
+
# Register the lightweight resource
|
33
|
+
resource_obj = lwrp
|
34
|
+
resource_obj.add_file(statement.file)
|
35
|
+
|
36
|
+
# Add the lightweight resource to the cookbook in which it is defined
|
37
|
+
cookbook_obj = cookbook
|
38
|
+
unless cookbook_obj.resources.include?(resource_obj)
|
39
|
+
cookbook_obj.resources.push(resource_obj)
|
40
|
+
end
|
41
|
+
|
42
|
+
# if multiple actions listed in same line, split the actions and
|
43
|
+
# register them
|
44
|
+
if statement.first_line =~ /,/
|
45
|
+
statement.first_line.split(%r{,?\s*:}).each do |action|
|
46
|
+
action = ChefObject.register(resource_obj, name, :action)
|
47
|
+
end
|
48
|
+
else
|
49
|
+
action = ChefObject.register(resource_obj, name, :action)
|
50
|
+
action.docstring = statement.docstring
|
51
|
+
end
|
52
|
+
|
53
|
+
log.info "Found [Actions] in #{parser.file.to_s}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,81 @@
|
|
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::Handlers
|
25
|
+
module Chef
|
26
|
+
# Handles "attributes" in cookbook metadata and lightweight resource.
|
27
|
+
#
|
28
|
+
class AttributeHandler < Base
|
29
|
+
handles method_call(:attribute)
|
30
|
+
|
31
|
+
# Process "attribute" keyword.
|
32
|
+
#
|
33
|
+
def process
|
34
|
+
# If file path includes metadata then handle cookbook attributes
|
35
|
+
# else handle resource attributes
|
36
|
+
if parser.file =~ /metadata\.rb/
|
37
|
+
namespace = cookbook
|
38
|
+
else
|
39
|
+
namespace = lwrp
|
40
|
+
namespace.add_file(statement.file)
|
41
|
+
|
42
|
+
cookbook_obj = cookbook
|
43
|
+
unless cookbook_obj.resources.include?(namespace)
|
44
|
+
cookbook_obj.resources.push(namespace)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Register attribute if not already registered
|
49
|
+
attrib_obj = ChefObject.register(namespace, name, :attribute)
|
50
|
+
attrib_obj.source = statement.source
|
51
|
+
attrib_obj.docstring = docstring
|
52
|
+
attrib_obj.add_file(statement.file, statement.line)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Get the docstring related to the attributes. The docstring is obtained
|
56
|
+
# from the ":description" field in the attribute.
|
57
|
+
#
|
58
|
+
# @return [YARD::Docstring] docstring for the attribute
|
59
|
+
#
|
60
|
+
def docstring
|
61
|
+
description = ""
|
62
|
+
path_array = parser.file.to_s.split('/')
|
63
|
+
if path_array.include?('metadata.rb')
|
64
|
+
# Suppose :description string have concatenation operator '+' then
|
65
|
+
# YARD builds an abstract syntax tree (AST). We need to traverse the
|
66
|
+
# tree to get the whole description string
|
67
|
+
statement.parameters[1].children.each do |ast_node|
|
68
|
+
if ast_node.jump(:ident).source == "description"
|
69
|
+
ast_node.traverse do |child|
|
70
|
+
description << child.jump(:string_content).source if child.type == :string_content
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
else
|
75
|
+
description = statement.comments
|
76
|
+
end
|
77
|
+
YARD::DocstringParser.new.parse(description).to_docstring
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,81 @@
|
|
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::Handlers
|
25
|
+
module Chef
|
26
|
+
# Base handler for chef elements.
|
27
|
+
#
|
28
|
+
class Base < YARD::Handlers::Ruby::Base
|
29
|
+
include YARD::CodeObjects::Chef
|
30
|
+
|
31
|
+
# Gets the name of the handled object.
|
32
|
+
#
|
33
|
+
def name
|
34
|
+
statement.parameters.first.jump(:string_content, :ident).source
|
35
|
+
end
|
36
|
+
|
37
|
+
# Registers the cookbook in {YARD::Registry} and returns the same.
|
38
|
+
#
|
39
|
+
# @return [CookbookObject] the CookbookObject
|
40
|
+
#
|
41
|
+
def cookbook
|
42
|
+
cookbook_name = ""
|
43
|
+
path_array = File.expand_path(statement.file).to_s.split('/')
|
44
|
+
if path_array.include?('metadata.rb')
|
45
|
+
cookbook_name = path_array[path_array.index('metadata.rb') - 1]
|
46
|
+
else
|
47
|
+
cookbook_name = path_array[path_array.length - 3]
|
48
|
+
end
|
49
|
+
ChefObject.register(CHEF, cookbook_name, :cookbook)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Registers the lightweight resource and provider in YARD::Registry and
|
53
|
+
# returns the same.
|
54
|
+
#
|
55
|
+
# @return [ResourceObject or ProviderObject] the lightweight resource or
|
56
|
+
# provider
|
57
|
+
#
|
58
|
+
def lwrp
|
59
|
+
path_array = File.expand_path(statement.file).to_s.split('/')
|
60
|
+
if path_array.include?("resources")
|
61
|
+
type = RESOURCE
|
62
|
+
type_sym = :resource
|
63
|
+
elsif path_array.include?("providers")
|
64
|
+
type = PROVIDER
|
65
|
+
type_sym = :provider
|
66
|
+
else
|
67
|
+
raise "Invalid LWRP type #{@path_array.join(',')}"
|
68
|
+
end
|
69
|
+
file_name = path_array.last.to_s.sub('.rb','')
|
70
|
+
|
71
|
+
cookbook_obj = cookbook
|
72
|
+
if file_name == "default"
|
73
|
+
lwrp_name = cookbook_obj.name
|
74
|
+
else
|
75
|
+
lwrp_name = "#{cookbook_obj.name}_#{file_name}"
|
76
|
+
end
|
77
|
+
ChefObject.register(type, lwrp_name, type_sym)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,94 @@
|
|
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::Handlers
|
25
|
+
module Chef
|
26
|
+
# Handles specific cookbook information like README, description and version.
|
27
|
+
#
|
28
|
+
class CookbookHandler < Base
|
29
|
+
handles method_call(:description)
|
30
|
+
handles method_call(:version)
|
31
|
+
|
32
|
+
def process
|
33
|
+
return unless statement.file.to_s =~ /metadata.rb/
|
34
|
+
|
35
|
+
# Register the cookbook
|
36
|
+
cookbook_obj = cookbook
|
37
|
+
cookbook_obj.add_file(statement.file)
|
38
|
+
case statement.first.source
|
39
|
+
when 'description'
|
40
|
+
cookbook_obj.short_desc = name
|
41
|
+
when 'version'
|
42
|
+
cookbook_obj.version = name
|
43
|
+
end
|
44
|
+
|
45
|
+
# Get the README file for the cookbook
|
46
|
+
base_dir = File.dirname(statement.file)
|
47
|
+
if cookbook_obj.docstring == ''
|
48
|
+
cookbook_obj.docstring, cookbook_obj.docstring_type = docstring(base_dir)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Get the top-level README for the cookbook repository if it exists
|
52
|
+
if CHEF.docstring == ''
|
53
|
+
readme_dir = File.expand_path('../..', base_dir)
|
54
|
+
CHEF.docstring, CHEF.docstring_type = docstring(readme_dir)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Get the name of the method being handled.
|
59
|
+
#
|
60
|
+
# @return [String] the method name
|
61
|
+
#
|
62
|
+
def name
|
63
|
+
string = ""
|
64
|
+
# YARD builds an abstract syntax tree (AST) which we need to traverse
|
65
|
+
# to obtain the complete docstring
|
66
|
+
statement.parameters.first.traverse do |child|
|
67
|
+
string << child.jump(:string_content).source if child.type == :string_content
|
68
|
+
end
|
69
|
+
string
|
70
|
+
end
|
71
|
+
|
72
|
+
# Generates docstring from the README file.
|
73
|
+
#
|
74
|
+
# @return [YARD::Docstring] the docstring
|
75
|
+
#
|
76
|
+
def docstring(base_dir)
|
77
|
+
type = ''
|
78
|
+
string = ''
|
79
|
+
readme_path = base_dir + '/README.md'
|
80
|
+
if File.exists?(readme_path)
|
81
|
+
type = :markdown
|
82
|
+
string = IO.read(readme_path)
|
83
|
+
else
|
84
|
+
readme_path = base_dir + '/README.rdoc'
|
85
|
+
if File.exists?(readme_path)
|
86
|
+
type = :rdoc
|
87
|
+
string = IO.read(readme_path)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
return YARD::DocstringParser.new.parse(string).to_docstring, type
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|