Sha256: 66f97acabfe0116148aa2ad7b1bee7e2c92cade2240793995dbbf6c6b203df00

Contents?: true

Size: 1.23 KB

Versions: 19

Compression:

Stored size: 1.23 KB

Contents

# Takes an optional content and an optional template name and returns the contents of a file.
Puppet::Functions.create_function(:'extlib::default_content') do
  # @param content
  # @param template_name
  #   The path to an .erb or .epp template file or `undef`.
  # @return
  #   Returns the value of the content parameter if it's a non empty string.
  #   Otherwise returns the rendered output from `template_name`.
  #   Returns `undef` if both `content` and `template_name` are `undef`.
  #
  # @example Using the function with a file resource.
  #   $config_file_content = default_content($file_content, $template_location)
  #   file { '/tmp/x':
  #     ensure  => 'file',
  #     content => $config_file_content,
  #   }
  dispatch :default_content do
    param 'Optional[String]', :content
    param 'Optional[String]', :template_name
    return_type 'Optional[String]'
  end

  def emptyish(x)
    x.nil? || x.empty? || x == :undef
  end

  def default_content(content = :undef, template_name = :undef)
    return content unless emptyish(content)

    unless emptyish(template_name)
      return call_function('template', template_name) unless template_name.end_with?('.epp')
      return call_function('epp', template_name)
    end

    :undef
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
puppet-debugger-1.4.0 spec/fixtures/modules/extlib/lib/puppet/functions/extlib/default_content.rb
puppet-debugger-1.3.0 spec/fixtures/modules/extlib/lib/puppet/functions/extlib/default_content.rb
puppet-debugger-1.2.0 spec/fixtures/modules/extlib/lib/puppet/functions/extlib/default_content.rb
puppet-debugger-1.1.0 spec/fixtures/modules/extlib/lib/puppet/functions/extlib/default_content.rb
puppet-debugger-1.0.0 spec/fixtures/modules/extlib/lib/puppet/functions/extlib/default_content.rb
puppet-debugger-0.19.0 spec/fixtures/modules/extlib/lib/puppet/functions/extlib/default_content.rb
puppet-debugger-0.18.0 spec/fixtures/modules/extlib/lib/puppet/functions/extlib/default_content.rb
puppet-debugger-0.17.0 spec/fixtures/modules/extlib/lib/puppet/functions/extlib/default_content.rb
puppet-debugger-0.16.0 spec/fixtures/modules/extlib/lib/puppet/functions/extlib/default_content.rb
puppet-debugger-0.15.2 spec/fixtures/modules/extlib/lib/puppet/functions/extlib/default_content.rb
puppet-debugger-0.15.1 spec/fixtures/modules/extlib/lib/puppet/functions/extlib/default_content.rb
puppet-debugger-0.15.0 spec/fixtures/modules/extlib/lib/puppet/functions/extlib/default_content.rb
puppet-debugger-0.14.0 spec/fixtures/modules/extlib/lib/puppet/functions/extlib/default_content.rb
puppet-debugger-0.13.0 spec/fixtures/modules/extlib/lib/puppet/functions/extlib/default_content.rb
puppet-debugger-0.12.3 spec/fixtures/modules/extlib/lib/puppet/functions/extlib/default_content.rb
puppet-debugger-0.12.2 spec/fixtures/modules/extlib/lib/puppet/functions/extlib/default_content.rb
puppet-debugger-0.12.1 spec/fixtures/modules/extlib/lib/puppet/functions/extlib/default_content.rb
puppet-debugger-0.12.0 spec/fixtures/modules/extlib/lib/puppet/functions/extlib/default_content.rb
puppet-debugger-0.11.0 spec/fixtures/modules/extlib/lib/puppet/functions/extlib/default_content.rb