lib/extensions/ar_virtual.rb
# define virtual_attribute for delegates
#
# this is called at schema load time (and not at class definition time)
#
# @param  method_name [Symbol] name of the attribute on the source class to be defined
# @param  col [Symbol] name of the attribute on the associated class to be referenced
# @option options :to [Symbol] name of the association from the source class to be referenced
# @option options :arel [Proc] (optional and not common)
# @option options :uses [Array|Symbol|Hash] sql includes hash. (default: to)
define virtual_attribute for delegates
this is called at schema load time (and not at class definition time)
define virtual_attribute for delegates this is called at schema load time ( and not at class definition time )
def define_virtual_delegate(method_name, col, options)
      unless (to = options[:to]) && (to_ref = reflection_with_virtual(to.to_s))
        raise ArgumentError, 'Delegation needs an association. Supply an options hash with a :to key as the last argument (e.g. delegate :hello, to: :greeter).'
      end
      col = col.to_s
      type = to_ref.klass.type_for_attribute(col)
      raise "unknown attribute #{to}##{col} referenced in #{name}" unless type
      arel = virtual_delegate_arel(col, to_ref)
      define_virtual_attribute(method_name, type, :uses => (options[:uses] || to), :arel => arel)
    end
def define_virtual_delegate ( method_name , col , options ) unless ( to = options [ :to ] ) && ( to_ref = reflection_with_virtual ( to . to_s ) ) raise ArgumentError , 'Delegation needs an association. Supply an options hash with a :to key as the last argument (e.g. delegate :hello, to: :greeter).' end col = col . to_s type = to_ref . klass . type_for_attribute ( col ) raise "unknown attribute #{to}##{col} referenced in #{name}" unless type arel = virtual_delegate_arel ( col , to_ref ) define_virtual_attribute ( method_name , type , :uses => ( options [ :uses ] || to ) , :arel => arel ) end
define virtual_attribute for delegates
this is called at schema load time (and not at class definition time)
define virtual_attribute for delegates this is called at schema load time ( and not at class definition time )
method_name
name of the attribute on the source class to be defined
name of the attribute on the source class to be defined
col
name of the attribute on the associated class to be referenced
name of the attribute on the associated class to be referenced
options
:uses  sql includes hash. (default: to)
: uses sql includes hash . ( default : to )