Sha256: a0ad7db489666a8b22e3a99447c03ee4f99cda82e5cd4b4985a02d513c614127

Contents?: true

Size: 865 Bytes

Versions: 39

Compression:

Stored size: 865 Bytes

Contents

# frozen_string_literal: true

module ActiveRecord
  class Relation
    class WhereClauseFactory # :nodoc:
      def initialize(klass, predicate_builder)
        @klass = klass
        @predicate_builder = predicate_builder
      end

      def build(opts, other)
        case opts
        when String, Array
          parts = [klass.sanitize_sql(other.empty? ? opts : ([opts] + other))]
        when Hash
          attributes = predicate_builder.resolve_column_aliases(opts)
          attributes.stringify_keys!

          parts = predicate_builder.build_from_hash(attributes)
        when Arel::Nodes::Node
          parts = [opts]
        else
          raise ArgumentError, "Unsupported argument type: #{opts} (#{opts.class})"
        end

        WhereClause.new(parts)
      end

      private
        attr_reader :klass, :predicate_builder
    end
  end
end

Version data entries

39 entries across 39 versions & 4 rubygems

Version Path
activerecord-6.0.6.1 lib/active_record/relation/where_clause_factory.rb
activerecord-6.0.6 lib/active_record/relation/where_clause_factory.rb
activerecord-6.0.5.1 lib/active_record/relation/where_clause_factory.rb
activerecord-6.0.5 lib/active_record/relation/where_clause_factory.rb
activerecord-6.0.4.8 lib/active_record/relation/where_clause_factory.rb
activerecord-6.0.4.7 lib/active_record/relation/where_clause_factory.rb
activerecord-6.0.4.6 lib/active_record/relation/where_clause_factory.rb
activerecord-6.0.4.5 lib/active_record/relation/where_clause_factory.rb
activerecord-6.0.4.4 lib/active_record/relation/where_clause_factory.rb
activerecord-6.0.4.3 lib/active_record/relation/where_clause_factory.rb
activerecord-6.0.4.2 lib/active_record/relation/where_clause_factory.rb
activerecord-6.0.4.1 lib/active_record/relation/where_clause_factory.rb
activerecord-6.0.4 lib/active_record/relation/where_clause_factory.rb
activerecord-6.0.3.7 lib/active_record/relation/where_clause_factory.rb
activerecord-6.0.3.6 lib/active_record/relation/where_clause_factory.rb
activerecord-6.0.3.5 lib/active_record/relation/where_clause_factory.rb
activerecord-6.0.3.4 lib/active_record/relation/where_clause_factory.rb
activerecord-6.0.3.3 lib/active_record/relation/where_clause_factory.rb
activerecord-6.0.3.2 lib/active_record/relation/where_clause_factory.rb
activerecord-6.0.3.1 lib/active_record/relation/where_clause_factory.rb