123456789_123456789_123456789_123456789_123456789_

Module: ActiveRecord::AttributeMethods::Query

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Defined in: activerecord/lib/active_record/attribute_methods/query.rb

Class Method Summary

::ActiveSupport::Concern - Extended

class_methods

Define class methods from given block.

included

Evaluate given block in context of base class, so that you can write class macros here.

prepended

Evaluate given block in context of base class, so that you can write class macros here.

append_features, prepend_features

Instance Method Summary

DSL Calls

included

[ GitHub ]


9
10
11
# File 'activerecord/lib/active_record/attribute_methods/query.rb', line 9

included do
  attribute_method_suffix "?", parameters: false
end

Instance Method Details

#_query_attribute(attr_name)

This method is for internal use only.
[ GitHub ]

  
# File 'activerecord/lib/active_record/attribute_methods/query.rb', line 19

def _query_attribute(attr_name) # :nodoc:
  value = self._read_attribute(attr_name.to_s)

  query_cast_attribute(attr_name, value)
end

#attribute?(attr_name) (private)

Alias for #query_attribute.

[ GitHub ]

  
# File 'activerecord/lib/active_record/attribute_methods/query.rb', line 25

alias :attribute? :query_attribute

#query_attribute(attr_name) Also known as: #attribute?

[ GitHub ]

  
# File 'activerecord/lib/active_record/attribute_methods/query.rb', line 13

def query_attribute(attr_name)
  value = self.public_send(attr_name)

  query_cast_attribute(attr_name, value)
end

#query_cast_attribute(attr_name, value) (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/attribute_methods/query.rb', line 29

def query_cast_attribute(attr_name, value)
  case value
  when true        then true
  when false, nil  then false
  else
    if !type_for_attribute(attr_name) { false }
      if Numeric === value || !value.match?(/[^0-9]/)
        !value.to_i.zero?
      else
        return false if ActiveModel::Type::Boolean::FALSE_VALUES.include?(value)
        !value.blank?
      end
    elsif value.respond_to?(:zero?)
      !value.zero?
    else
      !value.blank?
    end
  end
end