lib/rails/graphql/helpers/leaf_from_ar.rb
# Returns an Arel object that represents how this object is serialized
# direct from the query
#
# This happens in 3 parts
#
# 1. It finds a method to get the arel representation of the
#    accessor of the given attribute
# 2. If the attribute type mismatch the ar type or any of its aliases,
#    then invoke a adapter-specific cast
# 3. If necessary, adapters can describe a specific way to serialize
#    the arel attribute to ensure equivalency
#
# ==== Example
#
# Lets imagine a scenario where the adapter is the +PostgreSQL+, the
# attribute is a +data+ field with +enum+ type from a +sample+ table and
# the result must be a binary base64 data:
#
# 1. Sample.arel_attribute(:data)
#    # => "samples"."data"
# 2. Arel::Nodes::NamedFunction.new('CAST', [arel_object, Arel.sql('text')])
#    # => CAST("samples"."data" AS text)
# 3. Arel::Nodes::NamedFunction.new('ENCODE', [arel_object, Arel.sql("'base64")])
#    # => ENCODE(CAST("samples"."data" AS text), 'base64')
Returns an Arel object that represents how this object is serialized
direct from the query

This happens in 3 parts

1. It finds a method to get the arel representation of the
accessor of the given attribute
2. If the attribute type mismatch the ar type or any of its aliases,
then invoke a adapter-specific cast
3. If necessary, adapters can describe a specific way to serialize
the arel attribute to ensure equivalency

Example



1.
Returns an Arel object that represents how this object is serialized direct from the query This happens in 3 parts 1 . It finds a method to get the arel representation of the accessor of the given attribute 2 . If the attribute type mismatch the ar type or any of its aliases then invoke a adapter - specific cast 3 . If necessary adapters can describe a specific way to serialize the arel attribute to ensure equivalency Example 1 .
def from_ar(ar_object, attribute)
          key = adapter_key(ar_object)
          method_name = "from_#{key}_adapter"
          method_name = 'from_abstract_adapter' unless respond_to?(method_name, true)
          arel_object = send(method_name, ar_object, attribute)
          return if arel_object.nil?
          arel_object = try("cast_#{key}_attribute", arel_object, ar_adapter_type[key]) \
            unless match_ar_type?(ar_object, attribute, key)
          return if arel_object.nil?
          method_name = "#{key}_serialize"
          respond_to?(method_name, true) ? try(method_name, arel_object) : arel_object
        end
def from_ar ( ar_object , attribute ) key = adapter_key ( ar_object ) method_name = "from_#{key}_adapter" method_name = 'from_abstract_adapter' unless respond_to? ( method_name , true ) arel_object = send ( method_name , ar_object , attribute ) return if arel_object . nil? arel_object = try ( "cast_#{key}_attribute" , arel_object , ar_adapter_type [ key ] ) unless match_ar_type? ( ar_object , attribute , key ) return if arel_object . nil? method_name = "#{key}_serialize" respond_to? ( method_name , true ) ? try ( method_name , arel_object ) : arel_object end
Returns an Arel object that represents how this object is serialized
direct from the query
Returns an Arel object that represents how this object is serialized direct from the query
ar_object
attribute