Sha256: b81731c39ae821c2a99cdcbaf4beb640ab8ffcd4f978c078df1c034c11a30578

Contents?: true

Size: 1.51 KB

Versions: 71

Compression:

Stored size: 1.51 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 proc_for_binds
        -> value { ActiveModel::Attribute.with_cast_value(attribute.name, value, attribute.type_caster) }
      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

71 entries across 67 versions & 8 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/activerecord-7.0.8.7/lib/arel/nodes/homogeneous_in.rb
activerecord-7.0.8.7 lib/arel/nodes/homogeneous_in.rb
activerecord-7.0.8.6 lib/arel/nodes/homogeneous_in.rb
activerecord-6.1.7.10 lib/arel/nodes/homogeneous_in.rb
activerecord-6.1.7.9 lib/arel/nodes/homogeneous_in.rb
activerecord-7.0.8.5 lib/arel/nodes/homogeneous_in.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.8.4/lib/arel/nodes/homogeneous_in.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/activerecord-7.0.5.1/lib/arel/nodes/homogeneous_in.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/activerecord-7.0.5.1/lib/arel/nodes/homogeneous_in.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/activerecord-7.0.5.1/lib/arel/nodes/homogeneous_in.rb
activerecord-7.0.8.4 lib/arel/nodes/homogeneous_in.rb
activerecord-6.1.7.8 lib/arel/nodes/homogeneous_in.rb
activerecord-7.0.8.1 lib/arel/nodes/homogeneous_in.rb
activerecord-6.1.7.7 lib/arel/nodes/homogeneous_in.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activerecord-7.0.3.1/lib/arel/nodes/homogeneous_in.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activerecord-7.0.2.3/lib/arel/nodes/homogeneous_in.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activerecord-6.1.6.1/lib/arel/nodes/homogeneous_in.rb
activerecord-7.0.8 lib/arel/nodes/homogeneous_in.rb
activerecord-7.0.7.2 lib/arel/nodes/homogeneous_in.rb
activerecord-6.1.7.6 lib/arel/nodes/homogeneous_in.rb