Sha256: 76504752a9b403f66ed9d2e4a0c9adad9c85a6c582f06652204679aa21fee9f6

Contents?: true

Size: 868 Bytes

Versions: 31

Compression:

Stored size: 868 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

      protected

        attr_reader :klass, :predicate_builder
    end
  end
end

Version data entries

31 entries across 31 versions & 3 rubygems

Version Path
activerecord-5.2.8.1 lib/active_record/relation/where_clause_factory.rb
activerecord-5.2.8 lib/active_record/relation/where_clause_factory.rb
activerecord-5.2.7.1 lib/active_record/relation/where_clause_factory.rb
activerecord-5.2.7 lib/active_record/relation/where_clause_factory.rb
activerecord-5.2.6.3 lib/active_record/relation/where_clause_factory.rb
activerecord-5.2.6.2 lib/active_record/relation/where_clause_factory.rb
activerecord-5.2.6.1 lib/active_record/relation/where_clause_factory.rb
activerecord-5.2.6 lib/active_record/relation/where_clause_factory.rb
activerecord-5.2.4.6 lib/active_record/relation/where_clause_factory.rb
activerecord-5.2.5 lib/active_record/relation/where_clause_factory.rb
activerecord-5.2.4.5 lib/active_record/relation/where_clause_factory.rb
activerecord-5.2.4.4 lib/active_record/relation/where_clause_factory.rb
activerecord-5.2.4.3 lib/active_record/relation/where_clause_factory.rb
activerecord-5.2.4.2 lib/active_record/relation/where_clause_factory.rb
activerecord-5.2.4.1 lib/active_record/relation/where_clause_factory.rb
activerecord-5.2.4 lib/active_record/relation/where_clause_factory.rb
activerecord-5.2.4.rc1 lib/active_record/relation/where_clause_factory.rb
spiral_form-0.1.1 vendor/bundle/gems/activerecord-5.2.3/lib/active_record/relation/where_clause_factory.rb
spiral_form-0.1.0 vendor/bundle/gems/activerecord-5.2.3/lib/active_record/relation/where_clause_factory.rb
activerecord-5.2.3 lib/active_record/relation/where_clause_factory.rb