123456789_123456789_123456789_123456789_123456789_

Class: ActiveRecord::Relation::QueryAttribute

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: ActiveModel::Attribute
Defined in: activerecord/lib/active_record/relation/query_attribute.rb

Class Method Summary

::ActiveModel::Attribute - Inherited

.from_database, .from_user,
.new

This method should not be called directly.

.null, .uninitialized, .with_cast_value

Instance Attribute Summary

Instance Method Summary

Constructor Details

.newQueryAttribute

[ GitHub ]

  
# File 'activerecord/lib/active_record/relation/query_attribute.rb', line 8

def initialize(...)
  super

  # The query attribute value may be mutated before we actually "compile" the query.
  # To avoid that if the type uses a serializer we eagerly compute the value for database
  if value_before_type_cast.is_a?(StatementCache::Substitute)
    # we don't need to serialize StatementCache::Substitute
  elsif @type.serialized?
    value_for_database
  elsif @type.mutable? # If the type is simply mutable, we deep_dup it.
    @value_before_type_cast = @value_before_type_cast.deep_dup
  end
end

Instance Attribute Details

#infinite?Boolean (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/relation/query_attribute.rb', line 42

def infinite?
  infinity?(value_before_type_cast) || serializable? && infinity?(value_for_database)
end

#nil?Boolean (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/relation/query_attribute.rb', line 35

def nil?
  unless value_before_type_cast.is_a?(StatementCache::Substitute)
    value_before_type_cast.nil? ||
      type.respond_to?(:subtype) && serializable? && value_for_database.nil?
  end
end

#unboundable?Boolean (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/relation/query_attribute.rb', line 46

def unboundable?
  unless defined?(@_unboundable)
    serializable? { |value| @_unboundable = value <=> 0 } && @_unboundable = nil
  end
  @_unboundable
end

Instance Method Details

#==(other) Also known as: #eql?

[ GitHub ]

  
# File 'activerecord/lib/active_record/relation/query_attribute.rb', line 53

def ==(other)
  super && value_for_database == other.value_for_database
end

#eql?(other)

Alias for #==.

[ GitHub ]

  
# File 'activerecord/lib/active_record/relation/query_attribute.rb', line 56

alias eql? ==

#hash

[ GitHub ]

  
# File 'activerecord/lib/active_record/relation/query_attribute.rb', line 58

def hash
  [self.class, name, value_for_database, type].hash
end

#infinity?(value) ⇒ Boolean (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/relation/query_attribute.rb', line 63

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

#type_cast(value)

[ GitHub ]

  
# File 'activerecord/lib/active_record/relation/query_attribute.rb', line 22

def type_cast(value)
  value
end

#value_for_database

[ GitHub ]

  
# File 'activerecord/lib/active_record/relation/query_attribute.rb', line 26

def value_for_database
  @value_for_database = _value_for_database unless defined?(@value_for_database)
  @value_for_database
end

#with_cast_value(value)

[ GitHub ]

  
# File 'activerecord/lib/active_record/relation/query_attribute.rb', line 31

def with_cast_value(value)
  QueryAttribute.new(name, value, type)
end