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.
106 107 108 |
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 106 def initialize(name) super(PuppetStrings::Yard::CodeObjects::Types.instance, name) end |
Instance Attribute Details
#checks ⇒ Object (readonly)
Returns the value of attribute checks.
101 102 103 |
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 101 def checks @checks end |
#features ⇒ Object (readonly)
Returns the value of attribute features.
101 102 103 |
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 101 def features @features end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
101 102 103 |
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 101 def properties @properties end |
Instance Method Details
#add_check(check) ⇒ void
This method returns an undefined value.
Adds a check to the resource type.
143 144 145 146 |
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 143 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.
135 136 137 138 |
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 135 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
119 120 121 122 |
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 119 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
127 128 129 130 |
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 127 def add_property(property) @properties ||= [] @properties << property end |
#parameters ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 148 def 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 `#{self.name.to_s}` resource. You will seldom need " + \ "to specify this --- Puppet will usually discover the appropriate provider for your platform." ) @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
167 168 169 170 171 |
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 167 def providers providers = YARD::Registry.all("puppet_providers_#{name}".intern) return providers if providers.empty? providers.first.children end |
#to_hash ⇒ Hash
Converts the code object to a hash representation.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 175 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 { |p| p.name }.map(&:to_hash) if properties && !properties.empty? hash[:parameters] = parameters.sort_by { |p| p.name }.map(&:to_hash) if parameters && !parameters.empty? hash[:checks] = checks.sort_by { |c| c.name }.map(&:to_hash) if checks && !checks.empty? hash[:features] = features.sort_by { |f| f.name }.map(&:to_hash) if features && !features.empty? hash[:providers] = providers.sort_by { |p| p.name }.map(&:to_hash) if providers && !providers.empty? hash end |
#type ⇒ Object
Gets the type of the code object.
112 113 114 |
# File 'lib/puppet-strings/yard/code_objects/type.rb', line 112 def type :puppet_type end |