Class: ActiveRecord::VirtualAttributes::VirtualAttribute
- Inherits:
-
Arel::Nodes::Grouping
- Object
- Arel::Nodes::Grouping
- ActiveRecord::VirtualAttributes::VirtualAttribute
- Defined in:
- lib/active_record/virtual_attributes/virtual_arel.rb
Overview
VirtualArel associates arel with an attribute
Model.virtual_attribute :field, :string, :arel => ->(t) { t.grouping(t) } } Model.select(:field)
is equivalent to:
Model.select(Model.arel_table.grouping(Model.arel_table).as(:field)) Model.attribute_supported_by_sql?(:field) # => true
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#relation ⇒ Object
Returns the value of attribute relation.
Instance Method Summary collapse
-
#able_to_type_cast? ⇒ Boolean
rubocop:disable Rails/Delegate.
-
#initialize(arel, name = nil, relation = nil) ⇒ VirtualAttribute
constructor
A new instance of VirtualAttribute.
-
#lower ⇒ Object
Create a node for lowering this attribute.
- #type_cast_for_database(value) ⇒ Object
-
#type_caster ⇒ Object
methods from Arel::Nodes::Attribute.
Constructor Details
#initialize(arel, name = nil, relation = nil) ⇒ VirtualAttribute
Returns a new instance of VirtualAttribute.
14 15 16 17 18 |
# File 'lib/active_record/virtual_attributes/virtual_arel.rb', line 14 def initialize(arel, name = nil, relation = nil) super(arel) @name = name @relation = relation end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
20 21 22 |
# File 'lib/active_record/virtual_attributes/virtual_arel.rb', line 20 def name @name end |
#relation ⇒ Object
Returns the value of attribute relation.
20 21 22 |
# File 'lib/active_record/virtual_attributes/virtual_arel.rb', line 20 def relation @relation end |
Instance Method Details
#able_to_type_cast? ⇒ Boolean
rubocop:disable Rails/Delegate
37 38 39 |
# File 'lib/active_record/virtual_attributes/virtual_arel.rb', line 37 def able_to_type_cast? relation.able_to_type_cast? end |
#lower ⇒ Object
Create a node for lowering this attribute
28 29 30 |
# File 'lib/active_record/virtual_attributes/virtual_arel.rb', line 28 def lower relation.lower(self) end |
#type_cast_for_database(value) ⇒ Object
32 33 34 |
# File 'lib/active_record/virtual_attributes/virtual_arel.rb', line 32 def type_cast_for_database(value) relation.type_cast_for_database(name, value) end |
#type_caster ⇒ Object
methods from Arel::Nodes::Attribute
23 24 25 |
# File 'lib/active_record/virtual_attributes/virtual_arel.rb', line 23 def type_caster relation.type_for_attribute(name) end |