<commit_before>module Setup
  class Snippet < ReqRejValidator
    include SharedEditable
    include NamespaceNamed

    build_in_data_type.referenced_by(:namespace, :name)

    field :description, type: String
    field :type, type: Symbol, default: :javascript
    field :code, type: String

    has_and_belongs_to_many :tags, class_name: Setup::Tag.to_s, inverse_of: nil
    validates_presence_of :type

    before_save :validates_configuration

    def validates_configuration
      requires(:name, :code)
      errors.add(:type, 'is not valid') unless type_enum.has_value?(type)

      case type
        when :auto
          language = ::LanguageSniffer.detect(name, :content => code).language
          if language && type_enum.has_key?(language.name)
            type_ = type_enum[language.name]
          else
            type_ = 'text'
          end
          self.type = type_
      end

      errors.blank?
    end

    def type_enum
      {
          'Auto detect': :auto,
          'Plain text': :text,
          'APL': :apl,
          'ASCIIArmor': :asciiarmor,
          'ASN.1': :'asn.1',
          'Asterisk dialplan': :asterisk,
          'Brainfuck': :brainfuck,
          'C': :c,
          'C#': :cpp,
          'C++': :csharp,
          'Clojure': :clojure,
          'CMake': :cmake,
          'Cobol': :cobol,
          'CoffeeScript': :coffeescript,
          'Cold Fusion': :cfm,
          'Crystal': :crystal,
          'CSS': :css,
          'CSV': :csv,
          'Cypher': :cypher,
          'D': :d,
          'Dart': :dart,
          'Diff': :diff,
          'Docker': :dockerfile,
          'DTD': :dtd,<commit_msg>Minor bugfix<commit_after>module Setup
  class Snippet < ReqRejValidator
    include SharedEditable
    include NamespaceNamed

    build_in_data_type.referenced_by(:namespace, :name)

    field :description, type: String
    field :type, type: Symbol, default: :javascript
    field :code, type: String

    has_and_belongs_to_many :tags, class_name: Setup::Tag.to_s, inverse_of: nil
    validates_presence_of :type

    before_save :validates_configuration

    def validates_configuration
      requires(:name, :code)
      errors.add(:type, 'is not valid') unless type_enum.has_value?(type)

      case type
        when :auto
          language = ::LanguageSniffer.detect(name, :content => code).language
          if language && type_enum.has_key?(language.name)
            type_ = type_enum[language.name]
          else
            type_ = 'text'
          end
          self.type = type_
      end

      errors.blank?
    end

    def type_enum
      {
          'Auto detect': :auto,
          'Plain text': :text,
          'APL': :apl,
          'ASCIIArmor': :asciiarmor,
          'ASN.1': :'asn.1',
          'Asterisk dialplan': :asterisk,
          'Brainfuck': :brainfuck,
          'C': :c,
          'C++': :cpp,
          'C#': :csharp,
          'Clojure': :clojure,
          'CMake': :cmake,
          'Cobol': :cobol,
          'CoffeeScript': :coffeescript,
          'Cold Fusion': :cfm,
          'Crystal': :crystal,
          'CSS': :css,
          'CSV': :csv,
          'Cypher': :cypher,
          'D': :d,
          'Dart': :dart,
          'Diff': :diff,
          'Docker': :dockerfile,
          'DTD': :dtd,
{'fraction_non_alphanumeric': 0.12503793626707133, 'fraction_numerical': 0.0012139605462822458, 'mean_word_length': 1.9534050179211468, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3486578', 'n_tokens_mistral': 1104, 'n_tokens_neox': 1063, 'n_words': 242}