Skip to content

Commit ae9a323

Browse files
authored
Merge pull request #231 from scotje/227_provider_parameter_missing
(#227) Inject `provider` into params list for types with providers
2 parents 0937ee3 + 30ee744 commit ae9a323

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

lib/puppet-strings/yard/code_objects/type.rb

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def to_hash
9595
end
9696
end
9797

98-
attr_reader :properties, :parameters, :features
98+
attr_reader :properties, :features
9999

100100
# Initializes a new resource type.
101101
# @param [String] name The resource type name.
@@ -134,6 +134,31 @@ def add_feature(feature)
134134
@features << feature
135135
end
136136

137+
def parameters
138+
# just return params if there are no providers
139+
return @parameters if providers.empty?
140+
141+
# return existing params if we have already added provider
142+
return @parameters if @parameters.any? { |p| p.name == 'provider' }
143+
144+
provider_param = Parameter.new(
145+
'provider',
146+
"The specific backend to use for this `#{self.name.to_s}` resource. You will seldom need " + \
147+
"to specify this --- Puppet will usually discover the appropriate provider for your platform."
148+
)
149+
150+
@parameters << provider_param
151+
end
152+
153+
# Not sure if this is where this belongs or if providers should only be resolved at
154+
# render-time. For now, this should re-resolve on every call.
155+
# may be able to memoize this
156+
def providers
157+
providers = YARD::Registry.all("puppet_providers_#{name}".intern)
158+
return providers if providers.empty?
159+
providers.first.children
160+
end
161+
137162
# Converts the code object to a hash representation.
138163
# @return [Hash] Returns a hash representation of the code object.
139164
def to_hash
@@ -145,6 +170,7 @@ def to_hash
145170
hash[:properties] = properties.map(&:to_hash) if properties && !properties.empty?
146171
hash[:parameters] = parameters.map(&:to_hash) if parameters && !parameters.empty?
147172
hash[:features] = features.map(&:to_hash) if features && !features.empty?
173+
hash[:providers] = self.providers.map(&:to_hash) if providers && !providers.empty?
148174
hash
149175
end
150176
end

spec/fixtures/unit/markdown/output.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,10 @@ Whether or not to encrypt the database.
307307

308308
Default value: `false`
309309

310+
##### `provider`
311+
312+
The specific backend to use for this `database` resource. You will seldom need to specify this --- Puppet will usually discover the appropriate provider for your platform.
313+
310314
## Functions
311315

312316
### func

spec/fixtures/unit/markdown/output_with_data_types.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,10 @@ Whether or not to encrypt the database.
313313

314314
Default value: `false`
315315

316+
##### `provider`
317+
318+
The specific backend to use for this `database` resource. You will seldom need to specify this --- Puppet will usually discover the appropriate provider for your platform.
319+
316320
## Functions
317321

318322
### func

spec/fixtures/unit/markdown/output_with_plan.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,10 @@ Whether or not to encrypt the database.
311311

312312
Default value: `false`
313313

314+
##### `provider`
315+
316+
The specific backend to use for this `database` resource. You will seldom need to specify this --- Puppet will usually discover the appropriate provider for your platform.
317+
314318
## Functions
315319

316320
### func

0 commit comments

Comments
 (0)