Puppet::Type.newtype(:dism) do
  @doc = 'Manages Windows features via dism.'

  ensurable do
    desc 'Windows feature install state.'

    defaultvalues

    newvalue(:present) do
      provider.create
    end

    newvalue(:absent) do
      provider.destroy
    end
  end

  newparam(:name, :namevar => true) do
    desc 'The Windows feature name (case-sensitive).'
  end

  newparam(:answer) do
    desc 'The answer file for installing the feature.'
  end

  newparam(:all) do
    desc 'A flag indicating if we should install all dependencies or not.'
    newvalues(:true, :false)
    defaultto(false)

    munge do |value|
      resource.munge_boolean(value)
    end
  end

  newparam(:norestart) do
    desc 'Whether to disable restart if the feature specifies it should be restarted'
    newvalues(:true, :false)
    defaultto(true)

    munge do |value|
      resource.munge_boolean(value)
    end
  end

  newparam(:exitcode, :array_matching => :all) do
    desc 'DISM installation process exit code'
    # Ruby truncates exit codes to one bytes (https://bugs.ruby-lang.org/issues/8083)
    # so use truncated codes as workaround.
    #defaultto([0, 3010])
    defaultto([0, 3010, 3010 & 0xFF])
  end

  def munge_boolean(value)
    case value
      when true, "true", :true
        :true
      when false, "false", :false
        :false
      else
        fail("munge_boolean only takes booleans")
    end
  end
end

Puppet::Type.newtype(:dism) do
  @doc = 'Manages Windows features via dism.'

  ensurable

  newparam(:name, :namevar => true) do
    desc 'The Windows feature name (case-sensitive).'
  end

  newparam(:answer) do
    desc 'The answer file for installing the feature.'
  end

  newparam(:all) do
    desc 'A flag indicating if we should install all dependencies or not.'
    newvalues(:true, :false)
    defaultto(false)

    munge do |value|
      resource.munge_boolean(value)
    end
  end

  newparam(:norestart) do
    desc 'Whether to disable restart if the feature specifies it should be restarted'
    newvalues(:true, :false)
    defaultto(true)

    munge do |value|
      resource.munge_boolean(value)
    end
  end

  newparam(:exitcode, :array_matching => :all) do
    desc 'DISM installation process exit code'
    # Ruby truncates exit codes to one bytes (https://bugs.ruby-lang.org/issues/8083)
    # so use truncated codes as workaround.
    #defaultto([0, 3010])
    defaultto([0, 3010, 3010 & 0xFF])
  end

  def munge_boolean(value)
    case value
      when true, "true", :true
        :true
      when false, "false", :false
        :false
      else
        fail("munge_boolean only takes booleans")
    end
  end
end

Fix ensurable so it works with PE 2015.2, tested as working on 3.8 as well
Fix ensurable so it works with PE 2015.2, tested as working on 3.8 as well
