Class: ActiveRecord::VirtualAttributes::VirtualArel::ArelTableProxy

Inherits:
Arel::Table
  • Object
show all
Defined in:
lib/active_record/virtual_attributes/virtual_arel.rb

Overview

This arel table proxy is our shim to get our functionality into rails

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#klassObject

Returns the value of attribute klass.



21
22
23
# File 'lib/active_record/virtual_attributes/virtual_arel.rb', line 21

def klass
  @klass
end

Instance Method Details

#[](name, table = self) ⇒ Object

overrides Arel::Table#[] adds aliases and virtual attribute arel (aka sql)

for regular database columns:

returns an Arel::Attribute (just like Arel::Table#[])

for virtual attributes:

returns the arel for the value

for non sql friendly virtual attributes:

returns nil


33
34
35
36
37
38
39
40
41
42
# File 'lib/active_record/virtual_attributes/virtual_arel.rb', line 33

def [](name, table = self)
  if (col_alias = @klass.attribute_alias(name))
    name = col_alias
  end
  if @klass.virtual_attribute?(name)
    @klass.arel_for_virtual_attribute(name, table)
  else
    super
  end
end