Class: ActiveRecord::Relation::QueryAttribute
- Inherits:
-
ActiveModel::Attribute
- Object
- ActiveModel::Attribute
- ActiveRecord::Relation::QueryAttribute
- Defined in:
- lib/active_record/relation/query_attribute.rb
Overview
:nodoc:
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
- #infinite? ⇒ Boolean
-
#initialize ⇒ QueryAttribute
constructor
A new instance of QueryAttribute.
- #nil? ⇒ Boolean
- #type_cast(value) ⇒ Object
- #unboundable? ⇒ Boolean
- #value_for_database ⇒ Object
- #with_cast_value(value) ⇒ Object
Constructor Details
#initialize ⇒ QueryAttribute
Returns a new instance of QueryAttribute.
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File '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 Method Details
#==(other) ⇒ Object Also known as: eql?
52 53 54 |
# File 'lib/active_record/relation/query_attribute.rb', line 52 def ==(other) super && value_for_database == other.value_for_database end |
#hash ⇒ Object
57 58 59 |
# File 'lib/active_record/relation/query_attribute.rb', line 57 def hash [self.class, name, value_for_database, type].hash end |
#infinite? ⇒ Boolean
41 42 43 |
# File 'lib/active_record/relation/query_attribute.rb', line 41 def infinite? infinity?(value_before_type_cast) || serializable? && infinity?(value_for_database) end |
#nil? ⇒ Boolean
34 35 36 37 38 39 |
# File 'lib/active_record/relation/query_attribute.rb', line 34 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 |
#type_cast(value) ⇒ Object
22 23 24 |
# File 'lib/active_record/relation/query_attribute.rb', line 22 def type_cast(value) value end |
#unboundable? ⇒ Boolean
45 46 47 48 49 50 |
# File 'lib/active_record/relation/query_attribute.rb', line 45 def unboundable? unless defined?(@_unboundable) serializable? { |value| @_unboundable = value <=> 0 } && @_unboundable = nil end @_unboundable end |
#value_for_database ⇒ Object
26 27 28 |
# File 'lib/active_record/relation/query_attribute.rb', line 26 def value_for_database @value_for_database ||= super end |
#with_cast_value(value) ⇒ Object
30 31 32 |
# File 'lib/active_record/relation/query_attribute.rb', line 30 def with_cast_value(value) QueryAttribute.new(name, value, type) end |