Class: Arel::Project

Inherits:
Compound show all
Defined in:
lib/arel/algebra/relations/operations/project.rb

Instance Attribute Summary collapse

Attributes inherited from Compound

#engine, #relation

Attributes included from Relation

#count

Instance Method Summary collapse

Methods inherited from Compound

#column_for, #join?, #joins, #name, #skipped, #sources, #table, #table_alias, #table_sql, #taken, #unoperated_rows

Methods included from Relation

#[], #alias, #bind, #call, #compiler, #delete, #each, #exclusion_predicate_sql, #externalize, #find_attribute_matching_name, #from, #from_clauses, #group_clauses, #groupings, #having_clauses, #havings, #inclusion_predicate_sql, #insert, #inserts, #join, #join?, #joins, #lock, #locked, #order_clauses, #orders, #outer_join, #position_of, #primary_key, #project, #select_clauses, #session, #skip, #skipped, #sources, #take, #taken, #to_sql, #update, #where, #where_clauses, #wheres

Constructor Details

#initialize(relation, projections) ⇒ Project

Returns a new instance of Project.



5
6
7
8
9
10
# File 'lib/arel/algebra/relations/operations/project.rb', line 5

def initialize(relation, projections)
  super(relation)
  @projections = projections.map { |p| p.bind(relation) }
  @christener = Sql::Christener.new
  @attributes = Header.new(projections.map { |x| x.bind(self) })
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



3
4
5
# File 'lib/arel/algebra/relations/operations/project.rb', line 3

def attributes
  @attributes
end

#christenerObject (readonly)

Returns the value of attribute christener.



3
4
5
# File 'lib/arel/algebra/relations/operations/project.rb', line 3

def christener
  @christener
end

#projectionsObject (readonly)

Returns the value of attribute projections.



3
4
5
# File 'lib/arel/algebra/relations/operations/project.rb', line 3

def projections
  @projections
end

Instance Method Details

#evalObject



16
17
18
# File 'lib/arel/algebra/relations/operations/project.rb', line 16

def eval
  unoperated_rows.collect { |r| r.slice(*projections) }
end

#externalizable?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/arel/algebra/relations/operations/project.rb', line 12

def externalizable?
  attributes.any? { |a| a.respond_to?(:aggregation?) && a.aggregation? } || relation.externalizable?
end