Class: PuppetStrings::Yard::CodeObjects::Type
- Inherits:
-
Base
- Object
- YARD::CodeObjects::NamespaceObject
- Base
- PuppetStrings::Yard::CodeObjects::Type
- Defined in:
- lib/puppet-strings/yard/code_objects/type.rb
Overview
Implements the Puppet resource type code object.
Defined Under Namespace
Classes: Check, Feature, Parameter, Property
Instance Attribute Summary collapse
-
#checks ⇒ Object
readonly
Returns the value of attribute checks.
-
#features ⇒ Object
readonly
Returns the value of attribute features.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
Instance Method Summary collapse
-
#add_check(check) ⇒ void
Adds a check to the resource type.
-
#add_feature(feature) ⇒ void
Adds a feature to the resource type.
-
#add_parameter(parameter) ⇒ void
Adds a parameter to the resource type.
-
#add_property(property) ⇒ void
Adds a property to the resource type.
-
#initialize(name) ⇒ void
constructor
Initializes a new resource type.
- #parameters ⇒ Object
-
#providers ⇒ Object
Not sure if this is where this belongs or if providers should only be resolved at render-time.
-
#to_hash ⇒ Hash
Converts the code object to a hash representation.
-
#type ⇒ Object
Gets the type of the code object.
Methods inherited from Base
Constructor Details
#initialize(name) ⇒ void
Initializes a new resource type.
108 109 110 |
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 108 def initialize(name) super(PuppetStrings::Yard::CodeObjects::Types.instance, name) end |
Instance Attribute Details
#checks ⇒ Object (readonly)
Returns the value of attribute checks.
103 104 105 |
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 103 def checks @checks end |
#features ⇒ Object (readonly)
Returns the value of attribute features.
103 104 105 |
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 103 def features @features end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
103 104 105 |
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 103 def properties @properties end |
Instance Method Details
#add_check(check) ⇒ void
This method returns an undefined value.
Adds a check to the resource type.
145 146 147 148 |
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 145 def add_check(check) @checks ||= [] @checks << check end |
#add_feature(feature) ⇒ void
This method returns an undefined value.
Adds a feature to the resource type.
137 138 139 140 |
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 137 def add_feature(feature) @features ||= [] @features << feature end |
#add_parameter(parameter) ⇒ void
This method returns an undefined value.
Adds a parameter to the resource type
121 122 123 124 |
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 121 def add_parameter(parameter) @parameters ||= [] @parameters << parameter end |
#add_property(property) ⇒ void
This method returns an undefined value.
Adds a property to the resource type
129 130 131 132 |
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 129 def add_property(property) @properties ||= [] @properties << property end |
#parameters ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 150 def parameters @parameters ||= [] # guard against not filled parameters # just return params if there are no providers return @parameters if providers.empty? # return existing params if we have already added provider return @parameters if @parameters&.any? { |p| p.name == 'provider' } provider_param = Parameter.new( 'provider', "The specific backend to use for this `#{name}` resource. You will seldom need " \ 'to specify this --- Puppet will usually discover the appropriate provider for your platform.' ) @parameters ||= [] @parameters << provider_param end |
#providers ⇒ Object
Not sure if this is where this belongs or if providers should only be resolved at render-time. For now, this should re-resolve on every call. may be able to memoize this
171 172 173 174 175 176 |
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 171 def providers providers = YARD::Registry.all(:"puppet_providers_#{name}") return providers if providers.empty? providers.first.children end |
#to_hash ⇒ Hash
Converts the code object to a hash representation.
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 180 def to_hash hash = {} hash[:name] = name hash[:file] = file hash[:line] = line hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring) hash[:properties] = properties.sort_by(&:name).map(&:to_hash) if properties && !properties.empty? hash[:parameters] = parameters.sort_by(&:name).map(&:to_hash) if parameters && !parameters.empty? hash[:checks] = checks.sort_by(&:name).map(&:to_hash) if checks && !checks.empty? hash[:features] = features.sort_by(&:name).map(&:to_hash) if features && !features.empty? hash[:providers] = providers.sort_by(&:name).map(&:to_hash) if providers && !providers.empty? hash end |
#type ⇒ Object
Gets the type of the code object.
114 115 116 |
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 114 def type :puppet_type end |