Class: BatchAgg::ColumnProj

Inherits:
Object
  • Object
show all
Defined in:
lib/batchagg.rb

Instance Method Summary collapse

Constructor Details

#initialize(outer_table, model) ⇒ ColumnProj

Returns a new instance of ColumnProj.



78
79
80
81
# File 'lib/batchagg.rb', line 78

def initialize(outer_table, model)
  @outer_table = outer_table
  @attr_magic = AttrMagic.new(model, outer_table)
end

Instance Method Details

#build(defn, corr) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/batchagg.rb', line 83

def build(defn, corr)
  if defn.block?
    val = begin
      defn.block.call(@attr_magic)
    rescue StandardError
      nil
    end
    return val.as(defn.name.to_s) if val.is_a?(Arel::Attributes::Attribute) || val.is_a?(Arel::Nodes::SqlLiteral)

    rel = defn.block.call(corr)
    Arel.sql("(#{rel.to_sql})").as(defn.name.to_s)
  else
    @outer_table[defn.column].as(defn.name.to_s)
  end
end