-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathclass.rb
62 lines (54 loc) · 2.04 KB
/
class.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# frozen_string_literal: true
require 'puppet-strings/yard/code_objects/group'
# Implements the group for Puppet classes.
class PuppetStrings::Yard::CodeObjects::Classes < PuppetStrings::Yard::CodeObjects::Group
# Gets the singleton instance of the group.
# @return Returns the singleton instance of the group.
def self.instance
super(:puppet_classes)
end
# Gets the display name of the group.
# @param [Boolean] prefix whether to show a prefix. Ignored for Puppet group namespaces.
# @return [String] Returns the display name of the group.
def name(prefix = false)
'Puppet Classes'
end
end
# Implements the Puppet class code object.
class PuppetStrings::Yard::CodeObjects::Class < PuppetStrings::Yard::CodeObjects::Base
attr_reader :statement
attr_reader :parameters
# Initializes a Puppet class code object.
# @param [PuppetStrings::Parsers::ClassStatement] statement The class statement that was parsed.
# @return [void]
def initialize(statement)
@statement = statement
@parameters = statement.parameters.map { |p| [p.name, p.value] }
super(PuppetStrings::Yard::CodeObjects::Classes.instance, statement.name)
end
# Gets the type of the code object.
# @return Returns the type of the code object.
def type
:puppet_class
end
# Gets the source of the code object.
# @return Returns the source of the code object.
def source
@statement.source
end
# Converts the code object to a hash representation.
# @return [Hash] Returns a hash representation of the code object.
def to_hash
hash = {}
hash[:name] = name
hash[:file] = file
hash[:line] = line
hash[:inherits] = statement.parent_class if statement.parent_class
hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring)
defaults = Hash[*parameters.reject{ |p| p[1].nil? }.flatten]
hash[:defaults] = defaults unless defaults.nil? || defaults.empty?
#hash[:hiera_overrides] = hiera_overrides if hiera_overrides.any?
hash[:source] = source unless source.nil? || source.empty?
hash
end
end