<commit_before>module Eaco
  module Adapters
    module ActiveRecord

      ##
      # Sets up JSONB support for the different AR versions
      #
      class Compatibility
        autoload :V32, 'eaco/adapters/active_record/compatibility/v32.rb'
        autoload :V40, 'eaco/adapters/active_record/compatibility/v40.rb'
        autoload :V41, 'eaco/adapters/active_record/compatibility/v41.rb'
        autoload :V42, 'eaco/adapters/active_record/compatibility/v42.rb'
        autoload :V50, 'eaco/adapters/active_record/compatibility/v50.rb'

        autoload :Scoped, 'eaco/adapters/active_record/compatibility/scoped.rb'

        ##
        # Memoizes the given +model+ for later {#check!} calls.
        #
        # @param model [ActiveRecord::Base] the model to check
        #
        def initialize(model)
          @model = model
        end

        ##
        # Checks whether the target model is compatible.
        # Looks up the {#support_module} and includes it.
        #
        # @see #support_module
        #
        # @return [void]
        #
        def check!
          layer = support_module
          target.instance_eval { include layer }
        end

        private

        ##
        # @return [ActiveRecord::Base] associated with the model
        #
        def target
          target = @model.base_class.superclass
          if target == ApplicationRecord
            target.superclass
          else
            target
          end
        end

        ##
        # @return [String] the +ActiveRecord+ major and minor version numbers
        #
        # Example: "42" for 4.2
        #
        def active_record_version
          ver = target.parent.const_get(:VERSION)
          [ver.const_get(:MAJOR), ver.const_get(:MINOR)].join
        end

        ##
        # Tries to look up the support module for the {#active_record_version}
        # in the {Compatibility} namespace.
        #
        # @return [Module] the support module
        #
        # @raise [Eaco::Error] if not found.
        #
        # @see check!
        #
        def support_module
          unless self.class.const_defined?(support_module_name)<commit_msg>Use ActiveRecord directly, when we know we are using ActiveRecord<commit_after>module Eaco
  module Adapters
    module ActiveRecord

      ##
      # Sets up JSONB support for the different AR versions
      #
      class Compatibility
        autoload :V32, 'eaco/adapters/active_record/compatibility/v32.rb'
        autoload :V40, 'eaco/adapters/active_record/compatibility/v40.rb'
        autoload :V41, 'eaco/adapters/active_record/compatibility/v41.rb'
        autoload :V42, 'eaco/adapters/active_record/compatibility/v42.rb'
        autoload :V50, 'eaco/adapters/active_record/compatibility/v50.rb'

        autoload :Scoped, 'eaco/adapters/active_record/compatibility/scoped.rb'

        ##
        # Memoizes the given +model+ for later {#check!} calls.
        #
        # @param model [ActiveRecord::Base] the model to check
        #
        def initialize(model)
          @model = model
        end

        ##
        # Checks whether ActiveRecord::Base is compatible.
        # Looks up the {#support_module} and includes it.
        #
        # @see #support_module
        #
        # @return [void]
        #
        def check!
          layer = support_module
          ::ActiveRecord::Base.instance_eval { include layer }
        end

        private

        ##
        # @return [String] the +ActiveRecord+ major and minor version numbers
        #
        # Example: "42" for 4.2
        #
        def active_record_version
          [
            ::ActiveRecord::VERSION::MAJOR,
            ::ActiveRecord::VERSION::MINOR
          ].join
        end

        ##
        # Tries to look up the support module for the {#active_record_version}
        # in the {Compatibility} namespace.
        #
        # @return [Module] the support module
        #
        # @raise [Eaco::Error] if not found.
        #
        # @see check!
        #
        def support_module
          unless self.class.const_defined?(support_module_name)
{'fraction_non_alphanumeric': 0.08901285471743876, 'fraction_numerical': 0.011642008246422508, 'mean_word_length': 1.852005532503458, 'pattern_counts': {'":': 0, '<': 3, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2133711', 'n_tokens_mistral': 1229, 'n_tokens_neox': 1167, 'n_words': 287}