Sha256: c53555b4c884641f15d5f8c2a4c471988ca2b1d467b62861e56ee88e8fd41972

Contents?: true

Size: 1.37 KB

Versions: 9

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

module Arel # :nodoc: all
  module Nodes
    class HomogeneousIn < Node
      attr_reader :attribute, :values, :type

      def initialize(values, attribute, type)
        @values = values
        @attribute = attribute
        @type = type
      end

      def hash
        ivars.hash
      end

      def eql?(other)
        super || (self.class == other.class && self.ivars == other.ivars)
      end
      alias :== :eql?

      def equality?
        type == :in
      end

      def invert
        Arel::Nodes::HomogeneousIn.new(values, attribute, type == :in ? :notin : :in)
      end

      def left
        attribute
      end

      def right
        attribute.quoted_array(values)
      end

      def table_name
        attribute.relation.table_alias || attribute.relation.name
      end

      def column_name
        attribute.name
      end

      def casted_values
        type = attribute.type_caster

        casted_values = values.map do |raw_value|
          type.serialize(raw_value) if type.serializable?(raw_value)
        end

        casted_values.compact!
        casted_values
      end

      def fetch_attribute(&block)
        if attribute
          yield attribute
        else
          expr.fetch_attribute(&block)
        end
      end

      protected
        def ivars
          [@attribute, @values, @type]
        end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
activerecord-6.1.3.2 lib/arel/nodes/homogeneous_in.rb
activerecord-6.1.3.1 lib/arel/nodes/homogeneous_in.rb
activerecord-6.1.3 lib/arel/nodes/homogeneous_in.rb
activerecord-6.1.2.1 lib/arel/nodes/homogeneous_in.rb
activerecord-6.1.2 lib/arel/nodes/homogeneous_in.rb
activerecord-6.1.1 lib/arel/nodes/homogeneous_in.rb
activerecord-6.1.0 lib/arel/nodes/homogeneous_in.rb
activerecord-6.1.0.rc2 lib/arel/nodes/homogeneous_in.rb
activerecord-6.1.0.rc1 lib/arel/nodes/homogeneous_in.rb