Class: ArelQuery::WithHelper

Inherits:
Object
  • Object
show all
Defined in:
app/models/concerns/arel_query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, relation) ⇒ WithHelper

Returns a new instance of WithHelper.

Raises:

  • (ArgumentError)


21
22
23
24
25
26
27
# File 'app/models/concerns/arel_query.rb', line 21

def initialize(name, relation)
  raise ArgumentError, 'Name must be a Symbol or String' unless name.is_a?(Symbol) || name.is_a?(String)
  raise ArgumentError, 'Relation must be an Arel node or select manager' unless relation.is_a?(Arel::Nodes::Node) || relation.is_a?(Arel::SelectManager)

  @name     = name
  @relation = relation
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



19
20
21
# File 'app/models/concerns/arel_query.rb', line 19

def name
  @name
end

Instance Method Details

#[](column) ⇒ Object



29
30
31
# File 'app/models/concerns/arel_query.rb', line 29

def [](column)
  table[column]
end

#tableObject



33
34
35
# File 'app/models/concerns/arel_query.rb', line 33

def table
  @table ||= Arel::Table.new(@name)
end

#to_cteObject



37
38
39
# File 'app/models/concerns/arel_query.rb', line 37

def to_cte
  Arel::Nodes::Cte.new(@name, @relation)
end