Module: ArVirtualField::HelperMethods
- Defined in:
- lib/ar_virtual_field.rb
Class Method Summary collapse
- .select_append(relation, *values) ⇒ Object
- .table_name(name) ⇒ Object
- .table_with_column(name) ⇒ Object
- .unwrap_arel_expression(exp) ⇒ Object
- .wrap_to_lambda(exp) ⇒ Object
Class Method Details
.select_append(relation, *values) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/ar_virtual_field.rb', line 7 def self.select_append(relation, *values) if relation.select_values.empty? values.unshift(relation.arel_table[Arel.star]) end relation.select(*values) end |
.table_name(name) ⇒ Object
15 16 17 |
# File 'lib/ar_virtual_field.rb', line 15 def self.table_name(name) "#{name}_outer" end |
.table_with_column(name) ⇒ Object
19 20 21 |
# File 'lib/ar_virtual_field.rb', line 19 def self.table_with_column(name) "#{name}_outer.#{name}" end |
.unwrap_arel_expression(exp) ⇒ Object
23 24 25 26 27 |
# File 'lib/ar_virtual_field.rb', line 23 def self.unwrap_arel_expression(exp) Arel::Nodes::Grouping.new( exp.is_a?(Arel::Nodes::NodeExpression) ? exp : Arel.sql(exp) ) end |
.wrap_to_lambda(exp) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/ar_virtual_field.rb', line 29 def self.wrap_to_lambda(exp) case exp when Proc -> { HelperMethods.unwrap_arel_expression(exp.()) } else arel = HelperMethods.unwrap_arel_expression(exp) -> { arel } end end |