Sha256: ea031f66069a9f2a0ef4f53691c64aa1c4c0799f51e6bde2ef89edb9b1956505

Contents?: true

Size: 1.43 KB

Versions: 77

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

module Arel # :nodoc: all
  module Nodes
    class Casted < Arel::Nodes::NodeExpression # :nodoc:
      attr_reader :value, :attribute
      alias :value_before_type_cast :value

      def initialize(value, attribute)
        @value     = value
        @attribute = attribute
        super()
      end

      def nil?; value.nil?; end

      def value_for_database
        if attribute.able_to_type_cast?
          attribute.type_cast_for_database(value)
        else
          value
        end
      end

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

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

    class Quoted < Arel::Nodes::Unary # :nodoc:
      alias :value_for_database :value
      alias :value_before_type_cast :value

      def nil?; value.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::SelectManager, Arel::Nodes::SqlLiteral, ActiveModel::Attribute
        other
      else
        case attribute
        when Arel::Attributes::Attribute
          Casted.new other, attribute
        else
          Quoted.new other
        end
      end
    end
  end
end

Version data entries

77 entries across 74 versions & 7 rubygems

Version Path
activerecord-7.2.1 lib/arel/nodes/casted.rb
activerecord-7.2.0 lib/arel/nodes/casted.rb
activerecord-7.2.0.rc1 lib/arel/nodes/casted.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/arel/nodes/casted.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.8.4/lib/arel/nodes/casted.rb
activerecord-7.2.0.beta3 lib/arel/nodes/casted.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/activerecord-7.0.5.1/lib/arel/nodes/casted.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/activerecord-7.0.5.1/lib/arel/nodes/casted.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/activerecord-7.0.5.1/lib/arel/nodes/casted.rb
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/activerecord-7.1.3.4/lib/arel/nodes/casted.rb
activerecord-7.2.0.beta2 lib/arel/nodes/casted.rb
activerecord-7.1.3.4 lib/arel/nodes/casted.rb
activerecord-7.0.8.4 lib/arel/nodes/casted.rb
activerecord-7.2.0.beta1 lib/arel/nodes/casted.rb
activerecord-7.1.3.2 lib/arel/nodes/casted.rb
activerecord-7.1.3.1 lib/arel/nodes/casted.rb
activerecord-7.0.8.1 lib/arel/nodes/casted.rb
activerecord-7.1.3 lib/arel/nodes/casted.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activerecord-7.0.2.3/lib/arel/nodes/casted.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activerecord-7.0.3.1/lib/arel/nodes/casted.rb