Sha256: 75c1541f31e147d7956f78d65227cbee7fdb34541d5d713ba3a06f64fc5fbdc8

Contents?: true

Size: 1.17 KB

Versions: 39

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

module Arel # :nodoc: all
  module Nodes
    class Casted < Arel::Nodes::NodeExpression # :nodoc:
      attr_reader :val, :attribute
      def initialize(val, attribute)
        @val       = val
        @attribute = attribute
        super()
      end

      def nil?; @val.nil?; end

      def hash
        [self.class, val, attribute].hash
      end

      def eql?(other)
        self.class == other.class &&
            self.val == other.val &&
            self.attribute == other.attribute
      end
      alias :== :eql?
    end

    class Quoted < Arel::Nodes::Unary # :nodoc:
      alias :val :value
      def nil?; val.nil?; end

      def infinite?
        value.respond_to?(:infinite?) && value.infinite?
      end
    end

    def self.build_quoted(other, attribute = nil)
      case other
      when Arel::Nodes::Node, Arel::Attributes::Attribute, Arel::Table, Arel::Nodes::BindParam, Arel::SelectManager, Arel::Nodes::Quoted, Arel::Nodes::SqlLiteral
        other
      else
        case attribute
        when Arel::Attributes::Attribute
          Casted.new other, attribute
        else
          Quoted.new other
        end
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 4 rubygems

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