<commit_before>module ClassyEnum
  class SubclassNameError < StandardError; end

  class Base
    include Comparable
    include Conversion
    include Predicate
    include Translation
    include Collection

    class_attribute :base_class
    attr_accessor :owner, :serialize_as_json, :allow_blank

    class << self
      def inherited(klass)
        return if klass.anonymous?

        if self == ClassyEnum::Base
          klass.base_class = klass
        else

          # Ensure subclasses follow expected naming conventions
          unless klass.name.start_with? "#{base_class.name}::"
            raise SubclassNameError, "subclass must be namespaced with #{base_class.name}::"
          end

          # Add visit_EnumMember methods to support validates_uniqueness_of with enum field
          # This is due to a bug in Rails where it uses the method result as opposed to the
          # database value for validation scopes. A fix will be released in Rails 4, but
          # this will remain until Rails 3.x is no longer prevalent.
          if defined?(Arel::Visitors::ToSql)
            visitor_method = "visit_#{klass.name.split('::').join('_')}"

            Arel::Visitors::ToSql.class_eval do
              define_method visitor_method, lambda {|*values|
                values[0] = values[0].to_s
                quoted(*values)
              }
            end

            Arel::Visitors::DepthFirst.class_eval do
              define_method visitor_method, lambda {|*values|<commit_msg>Fixes Arel support for Rails 3.0<commit_after>module ClassyEnum
  class SubclassNameError < StandardError; end

  class Base
    include Comparable
    include Conversion
    include Predicate
    include Translation
    include Collection

    class_attribute :base_class
    attr_accessor :owner, :serialize_as_json, :allow_blank

    class << self
      def inherited(klass)
        return if klass.anonymous?

        if self == ClassyEnum::Base
          klass.base_class = klass
        else

          # Ensure subclasses follow expected naming conventions
          unless klass.name.start_with? "#{base_class.name}::"
            raise SubclassNameError, "subclass must be namespaced with #{base_class.name}::"
          end

          # Add visit_EnumMember methods to support validates_uniqueness_of with enum field
          # This is due to a bug in Rails where it uses the method result as opposed to the
          # database value for validation scopes. A fix will be released in Rails 4, but
          # this will remain until Rails 3.x is no longer prevalent.
          if defined?(Arel::Visitors::ToSql)
            visitor_method = "visit_#{klass.name.split('::').join('_')}"

            Arel::Visitors::ToSql.class_eval do
              define_method visitor_method, lambda {|*values|
                values[0] = values[0].to_s
                begin
                  quoted(*values)
                rescue NoMethodError
                  quote(*values)
                end
              }
            end

            Arel::Visitors::DepthFirst.class_eval do
              define_method visitor_method, lambda {|*values|
{'fraction_non_alphanumeric': 0.06981910504601714, 'fraction_numerical': 0.0031735956839098697, 'mean_word_length': 2.216326530612245, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2723536', 'n_tokens_mistral': 838, 'n_tokens_neox': 815, 'n_words': 261}