<commit_before>require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "puppet_x", "aptituz", "postfix.rb"))

Puppet::Type.type(:postfix_config).provide(:postconf) do

  commands :postconf => 'postconf'
  commands :postmulti => 'postmulti'

  def self.instances
    self.fetch_resources(nil)
  end

  def self.prefetch(resources)
    postfix_instances = resources.map { |name, resource| resource[:instance] }.uniq
    postfix_instances.each do |instance|
        settings = self.fetch_resources(instance)

        # match resources with same instance and key, not name since
        # this is not neccesarily distinct
        resources.each do |name, resource|
            if prov = settings.find { |entry| entry.key == resource[:key] and instance == resource[:instance] }
              resources[name].provider = prov
            end
        end
    end
  end

  def self.fetch_resources(instance)
    Puppetx::Aptituz::Postfix.get_postconf_entries(instance).collect do |name, value|
      new(  :name   => "#{name}",
          :key      => name,
          :value    => value,
          :ensure   => :present,
          :instance  => instance,
      )
    end

  end

  def exists?
    @property_hash[:ensure] == :present
  end

  mk_resource_methods

  def value=(value)
    Puppetx::Aptituz::Postfix.set_postconf_values(
       resource[:instance], { resource[:key] => value })
    @property_hash[:value] = value
  end

  def create
    Puppetx::Aptituz::Postfix.set_postconf_values(
       resource[:instance], { resource[:key] => value })
    @property_hash[:value] = resource[:value]
    @property_hash[:ensure] = :present
  end

  def destroy
    Puppetx::Aptituz::Postfix.remove_postconf_values(
      resource[:instance], resource[:key]
    )
  end

end<commit_msg>Bugfix: Actually Set value on create<commit_after>require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "puppet_x", "aptituz", "postfix.rb"))

Puppet::Type.type(:postfix_config).provide(:postconf) do

  commands :postconf => 'postconf'
  commands :postmulti => 'postmulti'

  def self.instances
    self.fetch_resources(nil)
  end

  def self.prefetch(resources)
    postfix_instances = resources.map { |name, resource| resource[:instance] }.uniq
    postfix_instances.each do |instance|
        settings = self.fetch_resources(instance)

        # match resources with same instance and key, not name since
        # this is not neccesarily distinct
        resources.each do |name, resource|
            if prov = settings.find { |entry| entry.key == resource[:key] and instance == resource[:instance] }
              resources[name].provider = prov
            end
        end
    end
  end

  def self.fetch_resources(instance)
    Puppetx::Aptituz::Postfix.get_postconf_entries(instance).collect do |name, value|
      new(  :name   => "#{name}",
          :key      => name,
          :value    => value,
          :ensure   => :present,
          :instance  => instance,
      )
    end

  end

  def exists?
    @property_hash[:ensure] == :present
  end

  mk_resource_methods

  def value=(value)
    Puppetx::Aptituz::Postfix.set_postconf_values(
       resource[:instance], { resource[:key] => value })
    @property_hash[:value] = value
  end

  def create
    Puppetx::Aptituz::Postfix.set_postconf_values(
       resource[:instance], { resource[:key] => resource[:value] })
    @property_hash[:value] = resource[:value]
    @property_hash[:ensure] = :present
  end

  def destroy
    Puppetx::Aptituz::Postfix.remove_postconf_values(
      resource[:instance], resource[:key]
    )
  end

end
{'fraction_non_alphanumeric': 0.1291390728476821, 'fraction_numerical': 0.0, 'mean_word_length': 3.0548098434004474, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3009394', 'n_tokens_mistral': 1148, 'n_tokens_neox': 1116, 'n_words': 236}