Module: ActiveRecord::VirtualAttributes::VirtualArel::ClassMethods
- Defined in:
- lib/active_record/virtual_attributes/virtual_arel.rb
Instance Method Summary collapse
-
#arel_for_virtual_attribute(column_name, table) ⇒ Nil|Arel::Nodes::Grouping
private api.
-
#arel_table ⇒ Object
ActiveRecord::Core 6.1.
-
#attribute_supported_by_sql?(name) ⇒ Boolean
supported by sql if any are true: - it is an attribute alias - it is an attribute that is non virtual - it is an attribute that is virtual and has arel defined.
Instance Method Details
#arel_for_virtual_attribute(column_name, table) ⇒ Nil|Arel::Nodes::Grouping
private api
98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/active_record/virtual_attributes/virtual_arel.rb', line 98 def arel_for_virtual_attribute(column_name, table) # :nodoc: arel_lambda = _virtual_arel[column_name.to_s] return unless arel_lambda arel = arel_lambda.call(table) # By convention, all attributes are defined with a grouping. # Since we're adding a VirtualAttribute node, which is essentially a # grouping, there is no need to keep both and end up with double parens arel = arel.expr if arel.kind_of?(Arel::Nodes::Grouping) VirtualAttribute.new(arel, column_name, table) end |
#arel_table ⇒ Object
ActiveRecord::Core 6.1
77 78 79 |
# File 'lib/active_record/virtual_attributes/virtual_arel.rb', line 77 def arel_table @arel_table ||= ArelTableProxy.new(table_name, :klass => self) end |
#attribute_supported_by_sql?(name) ⇒ Boolean
supported by sql if any are true:
-
it is an attribute alias
-
it is an attribute that is non virtual
-
it is an attribute that is virtual and has arel defined
85 86 87 88 89 |
# File 'lib/active_record/virtual_attributes/virtual_arel.rb', line 85 def attribute_supported_by_sql?(name) load_schema try(:attribute_alias?, name) || (has_attribute?(name) && (!virtual_attribute?(name) || !!_virtual_arel[name.to_s])) end |