<commit_before>require 'fileutils'

module ClassifyCluster
  module Writers
    class Puppet
      def self.export!(export_to_folder, options={})
        options = {:config_file => ClassifyCluster::Base.default_config_file}.merge(options)
        config = ClassifyCluster::Configurator::Configuration.new(options[:config_file])
        config.clusters.each_pair do |name, cluster|
          
          next if options[:cluster] && !(options[:cluster] == cluster.name.to_s)
          
          File.open(File.join(export_to_folder, "#{cluster.name}.pp"), 'w') do |file|
            cluster.nodes.each_pair do |fqdn, node|
              file.write(output(%Q%node "#{node.default? ? 'default' : node.fqdn}" {%))
              cluster.variables.each_pair do |key, value|
                file.write(output("$#{key}=#{value.inspect.gsub(/\$/, '\$')}", :indent => 1))
              end
              node.variables.each_pair do |key, value|
                file.write(output("$#{key}=#{value.inspect.gsub(/\$/, '\$')}", :indent => 1))
              end
              cluster.resources.each do |resource|
                file.write(output("#{resource.type} { #{resource.name.inspect}:", :indent => 1))
                resource.options.each_pair do |key, value|
                  file.write(output("#{key} => #{value.inspect},", :indent => 2))
                end
                file.write(output("}", :indent => 1))
              end
              node.resources.each do |resource|
                file.write(output("#{resource.type} { #{resource.name.inspect}:", :indent => 1))
                resource.options.each_pair do |key, value|
                  file.write(output("#{key} => #{value.inspect},", :indent => 2))
                end
                file.write(output("}", :indent => 1))
              end
              cluster.classes.each do |klass|
                file.write(output("include #{klass}", :indent => 1))
              end
              node.classes.each do |klass|
                file.write(output("include #{klass}", :indent => 1))
              end
              file.write(output("include socialcast", :indent => 1))
              file.write(output("}\n"))
            end
          end
        end; nil
      end
      private
      def self.output(string, options={})
        options = {:indent => 0}.merge(options)
        %Q%#{("\s" * 2) * options[:indent]}#{string}\n%
      end
    end
  end
end<commit_msg>Modified puppet writer to exclude variables with blank values<commit_after>require 'fileutils'

module ClassifyCluster
  module Writers
    class Puppet
      def self.export!(export_to_folder, options={})
        options = {:config_file => ClassifyCluster::Base.default_config_file}.merge(options)
        config = ClassifyCluster::Configurator::Configuration.new(options[:config_file])
        config.clusters.each_pair do |name, cluster|
          
          next if options[:cluster] && !(options[:cluster] == cluster.name.to_s)
          
          File.open(File.join(export_to_folder, "#{cluster.name}.pp"), 'w') do |file|
            cluster.nodes.each_pair do |fqdn, node|
              file.write(output(%Q%node "#{node.default? ? 'default' : node.fqdn}" {%))
              cluster.variables.each_pair do |key, value|
                file.write(output("$#{key}=#{value.inspect.gsub(/\$/, '\$')}", :indent => 1)) unless value.blank?
              end
              node.variables.each_pair do |key, value|
                file.write(output("$#{key}=#{value.inspect.gsub(/\$/, '\$')}", :indent => 1)) unless value.blank?
              end
              cluster.resources.each do |resource|
                file.write(output("#{resource.type} { #{resource.name.inspect}:", :indent => 1))
                resource.options.each_pair do |key, value|
                  file.write(output("#{key} => #{value.inspect},", :indent => 2)) unless value.blank?
                end
                file.write(output("}", :indent => 1))
              end
              node.resources.each do |resource|
                file.write(output("#{resource.type} { #{resource.name.inspect}:", :indent => 1))
                resource.options.each_pair do |key, value|
                  file.write(output("#{key} => #{value.inspect},", :indent => 2)) unless value.blank?
                end
                file.write(output("}", :indent => 1))
              end
              cluster.classes.each do |klass|
                file.write(output("include #{klass}", :indent => 1))
              end
              node.classes.each do |klass|
                file.write(output("include #{klass}", :indent => 1))
              end
              file.write(output("include socialcast", :indent => 1))
              file.write(output("}\n"))
            end
          end
        end; nil
      end
      private
      def self.output(string, options={})
        options = {:indent => 0}.merge(options)
        %Q%#{("\s" * 2) * options[:indent]}#{string}\n%
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.16012810248198558, 'fraction_numerical': 0.005204163330664532, 'mean_word_length': 1.9480825958702064, 'pattern_counts': {'":': 0, '<': 3, '<?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': '352405', 'n_tokens_mistral': 1444, 'n_tokens_neox': 1414, 'n_words': 283}