Skip to content

Commit

Permalink
(#227) Inject provider into params list for types with providers
Browse files Browse the repository at this point in the history
  • Loading branch information
scotje committed Apr 24, 2020
1 parent 0937ee3 commit 53368a8
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion lib/puppet-strings/yard/code_objects/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def to_hash
end
end

attr_reader :properties, :parameters, :features
attr_reader :properties, :features

# Initializes a new resource type.
# @param [String] name The resource type name.
Expand Down Expand Up @@ -134,6 +134,31 @@ def add_feature(feature)
@features << feature
end

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

# 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
def providers
providers = YARD::Registry.all("puppet_providers_#{name}".intern)
return providers if providers.empty?
providers.first.children
end

# Converts the code object to a hash representation.
# @return [Hash] Returns a hash representation of the code object.
def to_hash
Expand All @@ -145,6 +170,7 @@ def to_hash
hash[:properties] = properties.map(&:to_hash) if properties && !properties.empty?
hash[:parameters] = parameters.map(&:to_hash) if parameters && !parameters.empty?
hash[:features] = features.map(&:to_hash) if features && !features.empty?
hash[:providers] = self.providers.map(&:to_hash) if providers && !providers.empty?
hash
end
end

0 comments on commit 53368a8

Please sign in to comment.