<commit_before>require 'puppet/provider/parsedfile'

Puppet::Type.type(:collectd_conf).provide(:parsed,
	:parent => Puppet::Provider::ParsedFile,
	:default_target => "/etc/collectd/collectd.conf"
	) do

	text_line :comment, :match => %r{^#}

	text_line :blank, :match => %r{^\s*$}

	plugin = record_line :plugin_start, :fields => %w{name},
		:match => %r{^\s*<Plugin\s+(.*)\s*>\s*$}

	class << plugin
		def to_line(record)
			"<Plugin %s>\n%s\n</Plugin>" % [
				record[:name],
				record[:contents].join("\n")
			]
		end
	end

	record_line :plugin_end, :fields => [],
		:match => %r{^\s*</Plugin>\s*$}

	config = record_line :parsed, :fields => %w{name value},
		:match => %r{^\s*(\S+)\s+(.*)$}

	class << config
		def to_line(record)
			values = [ record[:value] ]
			if record[:value].is_a? Array 
				values = record[:value]
			end
			values.collect do |v| "%s %s" % [ record[:name], v ] end.join("\n")
		end
	end

	# coalesce configuration directives with multiple values
	def self.prefetch_hook(records)

		sorted_records = {}
		plugins = []

		plugin = nil
		contents = nil
		records.each { |record|

			case record[:record_type]
			when :plugin_start
				# start collecting lines within the <Plugin><commit_msg>Sort values to stabilise conf file<commit_after>require 'puppet/provider/parsedfile'

Puppet::Type.type(:collectd_conf).provide(:parsed,
	:parent => Puppet::Provider::ParsedFile,
	:default_target => "/etc/collectd/collectd.conf"
	) do

	text_line :comment, :match => %r{^#}

	text_line :blank, :match => %r{^\s*$}

	plugin = record_line :plugin_start, :fields => %w{name},
		:match => %r{^\s*<Plugin\s+(.*)\s*>\s*$}

	class << plugin
		def to_line(record)
			"<Plugin %s>\n%s\n</Plugin>" % [
				record[:name],
				record[:contents].join("\n")
			]
		end
	end

	record_line :plugin_end, :fields => [],
		:match => %r{^\s*</Plugin>\s*$}

	config = record_line :parsed, :fields => %w{name value},
		:match => %r{^\s*(\S+)\s+(.*)$}

	class << config
		def to_line(record)
			values = [ record[:value] ]
			if record[:value].is_a? Array 
				values = record[:value]
			end
			values.collect do |v| "%s %s" % [ record[:name], v ] end.sort.join("\n")
		end
	end

	# coalesce configuration directives with multiple values
	def self.prefetch_hook(records)

		sorted_records = {}
		plugins = []

		plugin = nil
		contents = nil
		records.each { |record|

			case record[:record_type]
			when :plugin_start
				# start collecting lines within the <Plugin>
{'fraction_non_alphanumeric': 0.1911525974025974, 'fraction_numerical': 0.0, 'mean_word_length': 3.8428290766208253, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 33, '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': '4661837', 'n_tokens_mistral': 1006, 'n_tokens_neox': 901, 'n_words': 192}