<commit_before>require_relative '../xlr_rest_provider.rb'

Puppet::Type.type(:xlrelease_config_item).provide :rest, :parent => Puppet::Provider::XLReleaseRestProvider do

  has_feature :restclient


  def self.instances
    xlrelease_config_items = rest_get "configurations".collect do |config_hash|
      new( :type        => config_hash["type"],
           :title       => config_hash["title"],
           :properties  => config_hash["properties"],
           :ensure      => :present,
           :id          => config_hash["id"]
      )
    end
  end

  def self.prefetch(resources)
    xlrelease_config_items = instances
    resources.keys.each do |title|
      if provider = xlrelease_config_items.find{ |cfi| cfi.title == title }
        resources[name].provider = provider
      end
    end
  end

  def create
    property_json = {
        :type        => resource[:type],
        :title       => resource[:title],
        :properties  => resource[:properties],
        :ensure      => :present,
        }.to_j
    rest_post "configurations" property_json
    @property_hash[:ensure] = :present
  end

  def destroy
    rest_delete "configurations/#{@property_hash[:id]}"
    @property_hash[:ensure] = :absent
  end

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

  def type
    @property_hash[:type]
  end

  def type=(value)
    @property_flush[:type] = value
  end

  def properties
    @property_hash[:properties] || {}
  end

  def properties=(value)
    @property_flush[:properties] = properties.merge(value)
  end

  def initialize(value={})
    super(value)
    @property_flush = {}
  end

  def flush
    options {}
    if @property_flush
      options = {
          :type        => resource[:type],
          :title       => resource[:title],
          :properties  => resource[:properties],
          :ensure      => :present,
      }
    rest_put "configurations/#{@property_hash[:id]}" options.to_j
    end
  end


end<commit_msg> added some ci stuff<commit_after>require_relative '../xlr_rest_provider.rb'

Puppet::Type.type(:xlrelease_config_item).provide :rest, :parent => Puppet::Provider::XLReleaseRestProvider do

  has_feature :restclient


  def self.instances
    xlrelease_config_items = rest_get "configurations".collect do |config_hash|
      new( :type        => config_hash["type"],
           :title       => config_hash["title"],
           :properties  => config_hash["properties"],
           :ensure      => :present,
           :id          => config_hash["id"]
      )
    end
  end

  def self.prefetch(resources)
    xlrelease_config_items = instances
    resources.keys.each do |title|
      if provider = xlrelease_config_items.find{ |cfi| cfi.title == title }
        resources[name].provider = provider
      end
    end
  end

  def create
    property_json = {
        :type        => resource[:type],
        :title       => resource[:title],
        :properties  => resource[:properties],
        :ensure      => :present,
        }.to_j
    rest_post "configurations", property_json
    @property_hash[:ensure] = :present
  end

  def destroy
    rest_delete "configurations/#{@property_hash[:id]}"
    @property_hash[:ensure] = :absent
  end

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

  def type
    @property_hash[:type]
  end

  def type=(value)
    @property_flush[:type] = value
  end

  def properties
    @property_hash[:properties] || {}
  end

  def properties=(value)
    @property_flush[:properties] = properties.merge(value)
  end

  def initialize(value={})
    super(value)
    @property_flush = {}
  end

  def flush
    options {}
    if @property_flush
      options = {
          :type        => resource[:type],
          :title       => resource[:title],
          :properties  => resource[:properties],
          :ensure      => :present,
      }
    rest_put "configurations/#{@property_hash[:id]}", options.to_j
    end
  end


end
{'fraction_non_alphanumeric': 0.12179649835067242, 'fraction_numerical': 0.0, 'mean_word_length': 2.5417789757412397, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, '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': '6195662', 'n_tokens_mistral': 1198, 'n_tokens_neox': 1159, 'n_words': 243}