Sha256: 61c388017f1c9e11d59ad42dc7ec1cf5ca4b877c62ba3fe9f639bee798b1b1e9

Contents?: true

Size: 1.03 KB

Versions: 33

Compression:

Stored size: 1.03 KB

Contents

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

      def build(opts, other)
        binds = []

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

          attributes, binds = predicate_builder.create_binds(attributes)

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

        WhereClause.new(parts, binds)
      end

      protected

      attr_reader :klass, :predicate_builder
    end
  end
end

Version data entries

33 entries across 33 versions & 4 rubygems

Version Path
activerecord-5.0.7.2 lib/active_record/relation/where_clause_factory.rb
activerecord-5.0.7.1 lib/active_record/relation/where_clause_factory.rb
activerecord-5.0.7 lib/active_record/relation/where_clause_factory.rb
activerecord-5.0.6 lib/active_record/relation/where_clause_factory.rb
activerecord-5.0.6.rc1 lib/active_record/relation/where_clause_factory.rb
activerecord-5.0.5 lib/active_record/relation/where_clause_factory.rb
activerecord-5.0.5.rc2 lib/active_record/relation/where_clause_factory.rb
activerecord-5.0.5.rc1 lib/active_record/relation/where_clause_factory.rb
activerecord-5.0.4 lib/active_record/relation/where_clause_factory.rb
activerecord-5.0.4.rc1 lib/active_record/relation/where_clause_factory.rb
activerecord-5.0.3 lib/active_record/relation/where_clause_factory.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/activerecord-5.0.2/lib/active_record/relation/where_clause_factory.rb
activerecord-5.0.2 lib/active_record/relation/where_clause_factory.rb
activerecord-5.0.2.rc1 lib/active_record/relation/where_clause_factory.rb
autocompl-0.2.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/relation/where_clause_factory.rb
autocompl-0.2.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/relation/where_clause_factory.rb
autocompl-0.2.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/relation/where_clause_factory.rb
autocompl-0.1.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/relation/where_clause_factory.rb
autocompl-0.1.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/relation/where_clause_factory.rb
autocompl-0.1.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/relation/where_clause_factory.rb