<commit_before>require 'baby_squeel/operators'

module BabySqueel
  module Nodes
    class << self
      # Wraps an Arel node in a Proxy so that it can
      # be extended.
      def wrap(arel)
        if arel.class.parents.include?(Arel)
          Generic.new(arel)
        else
          arel
        end
      end

      # Unwraps a BabySqueel::Proxy before being passed to
      # ActiveRecord.
      def unwrap(node)
        if node.respond_to? :_arel
          node._arel
        elsif node.is_a? Array
          node.map { |n| unwrap(n) }
        else
          node
        end
      end
    end

    # This proxy class allows us to quack like any arel object. When a
    # method missing is hit, we'll instantiate a new proxy object.
    class Proxy < ActiveSupport::ProxyObject
      # Resolve constants the normal way
      def self.const_missing(name)
        ::Object.const_get(name)
      end

      attr_reader :_arel

      def initialize(arel)
        @_arel = Nodes.unwrap(arel)
      end

      def respond_to?(meth, include_private = false)
        meth.to_s == '_arel' || _arel.respond_to?(meth, include_private)
      end

      private

      def method_missing(meth, *args, &block)
        if _arel.respond_to?(meth)
          Nodes.wrap _arel.send(meth, *Nodes.unwrap(args), &block)
        else
          super
        end
      end
    end

    # This is a generic proxy class that includes all possible modules.
    # In the future, these proxy classes should be more specific and only
    # include necessary/applicable modules.
    class Generic < Proxy
      extend Operators::ArelAliasing
      include Arel::OrderPredications<commit_msg>Include Arel::AliasPredication on the generic node to allow aliasing an infix operation<commit_after>require 'baby_squeel/operators'

module BabySqueel
  module Nodes
    class << self
      # Wraps an Arel node in a Proxy so that it can
      # be extended.
      def wrap(arel)
        if arel.class.parents.include?(Arel)
          Generic.new(arel)
        else
          arel
        end
      end

      # Unwraps a BabySqueel::Proxy before being passed to
      # ActiveRecord.
      def unwrap(node)
        if node.respond_to? :_arel
          node._arel
        elsif node.is_a? Array
          node.map { |n| unwrap(n) }
        else
          node
        end
      end
    end

    # This proxy class allows us to quack like any arel object. When a
    # method missing is hit, we'll instantiate a new proxy object.
    class Proxy < ActiveSupport::ProxyObject
      # Resolve constants the normal way
      def self.const_missing(name)
        ::Object.const_get(name)
      end

      attr_reader :_arel

      def initialize(arel)
        @_arel = Nodes.unwrap(arel)
      end

      def respond_to?(meth, include_private = false)
        meth.to_s == '_arel' || _arel.respond_to?(meth, include_private)
      end

      private

      def method_missing(meth, *args, &block)
        if _arel.respond_to?(meth)
          Nodes.wrap _arel.send(meth, *Nodes.unwrap(args), &block)
        else
          super
        end
      end
    end

    # This is a generic proxy class that includes all possible modules.
    # In the future, these proxy classes should be more specific and only
    # include necessary/applicable modules.
    class Generic < Proxy
      extend Operators::ArelAliasing
      include Arel::AliasPredication
      include Arel::OrderPredications
{'fraction_non_alphanumeric': 0.06954505940307157, 'fraction_numerical': 0.0, 'mean_word_length': 2.0876565295169947, 'pattern_counts': {'":': 0, '<': 11, '<?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': '7286120', 'n_tokens_mistral': 1026, 'n_tokens_neox': 1001, 'n_words': 322}