<commit_before>Puppet::Type.type(:influxdb_database).provide(:ruby) do
  desc 'Manages InfluxDB databases.'

commands :influx_cli => '/opt/influxdb/influx'

def get_database_list()
  begin
    output = influx_cli(['-execute', 'show databases'])
  rescue Puppet::ExecutionFailure => e
    Puppet.debug("#get_database_list had an error -> #{e.inspect}")
    return nil
  end
  databases = output.split("\n")[2..-1]
  Puppet.debug("#get_database_list output -> #{databases}")
  databases
end

def exists?
  dbs = get_database_list()
  dbs.include? resource[:name]
end

def create
  influx_cli(['-execute', "create database #{resource[:name]}"].compact)
end

def destroy
  influx_cli(['-execute', "drop database #{resource[:name]}"].compact)
end

end<commit_msg>better provider for database. Puppet resources compatible<commit_after>Puppet::Type.type(:influxdb_database).provide(:ruby) do
  desc 'Manages InfluxDB databases.'

  commands :influx_cli => '/opt/influxdb/influx'

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

  def self.instances
    begin
      output = influx_cli(['-execute', 'show databases'])
    rescue Puppet::ExecutionFailure => e
      return nil
    end
    databases = output.split("\n")[3..-1]
    databases.collect do |name|
      new(:name    => name,
        :ensure  => :present,
      )
    end
  end

  def self.prefetch(resources)
    instances.each do |prov|
      if resource = resources[prov.name]
        resource.provider = prov
      end
    end
  end

  def flush
    if @property_flush[:ensure] == :absent
        influx_cli(['-execute', "drop database #{resource[:name]}"].compact)
        return
    end
    influx_cli(['-execute', "create database #{resource[:name]}"].compact)
  end

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

  def create
    @property_flush[:ensure] = :present
  end

  def destroy
    @property_flush[:ensure] = :absent
  end

end
{'fraction_non_alphanumeric': 0.13963039014373715, 'fraction_numerical': 0.002053388090349076, 'mean_word_length': 3.5325581395348835, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '2970451', 'n_tokens_mistral': 650, 'n_tokens_neox': 629, 'n_words': 145}