<commit_before>require 'rubygems' if RUBY_VERSION < '1.9.0' && Puppet.version < '3'
require 'json' if Puppet.features.json?

begin
  require 'puppet_x/sensu/to_type'
rescue LoadError => e
  libdir = Pathname.new(__FILE__).parent.parent.parent.parent
  require File.join(libdir, 'puppet_x/sensu/to_type')
end

Puppet::Type.type(:sensu_client_config).provide(:json) do
  confine :feature => :json
  include Puppet_X::Sensu::Totype

  def conf
    begin
      @conf ||= JSON.parse(File.read(config_file))
    rescue
      @conf ||= {}
    end
  end

  def flush
    File.open(config_file, 'w') do |f|
      f.puts JSON.pretty_generate(conf)
    end
  end

  def config_file
    "#{resource[:base_path]}/client.json"
  end

  def create
    conf['client'] = {}
    self.client_name = resource[:client_name]
    self.address = resource[:address]
    self.bind = resource[:bind]
    self.subscriptions = resource[:subscriptions]
    self.safe_mode = resource[:safe_mode]
    self.custom = resource[:custom] unless resource[:custom].nil?
    self.keepalive = resource[:keepalive] unless resource[:keepalive].nil?
  end

  def destroy
    @conf = nil
  end

  def exists?
    conf.has_key?('client')
  end

  def check_args
    ['name', 'address', 'subscriptions', 'safe_mode', 'bind', 'keepalive']
  end

  def client_name
    conf['client']['name']
  end
<commit_msg>Add port to check_args so it doesn't gets cleared by custom property<commit_after>require 'rubygems' if RUBY_VERSION < '1.9.0' && Puppet.version < '3'
require 'json' if Puppet.features.json?

begin
  require 'puppet_x/sensu/to_type'
rescue LoadError => e
  libdir = Pathname.new(__FILE__).parent.parent.parent.parent
  require File.join(libdir, 'puppet_x/sensu/to_type')
end

Puppet::Type.type(:sensu_client_config).provide(:json) do
  confine :feature => :json
  include Puppet_X::Sensu::Totype

  def conf
    begin
      @conf ||= JSON.parse(File.read(config_file))
    rescue
      @conf ||= {}
    end
  end

  def flush
    File.open(config_file, 'w') do |f|
      f.puts JSON.pretty_generate(conf)
    end
  end

  def config_file
    "#{resource[:base_path]}/client.json"
  end

  def create
    conf['client'] = {}
    self.client_name = resource[:client_name]
    self.address = resource[:address]
    self.bind = resource[:bind]
    self.subscriptions = resource[:subscriptions]
    self.safe_mode = resource[:safe_mode]
    self.custom = resource[:custom] unless resource[:custom].nil?
    self.keepalive = resource[:keepalive] unless resource[:keepalive].nil?
  end

  def destroy
    @conf = nil
  end

  def exists?
    conf.has_key?('client')
  end

  def check_args
    ['name', 'address', 'subscriptions', 'safe_mode', 'bind', 'keepalive', 'port']
  end

  def client_name
    conf['client']['name']
  end

{'fraction_non_alphanumeric': 0.13572710951526032, 'fraction_numerical': 0.002872531418312388, 'mean_word_length': 3.6666666666666665, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '4035014', 'n_tokens_mistral': 997, 'n_tokens_neox': 971, 'n_words': 206}