Class: Arel::Attribute

Inherits:
Object
  • Object
show all
Includes:
Congruence, Expressions, Orderings, Predications, Transformations, Types
Defined in:
lib/arel/engines/sql/primitives.rb,
lib/arel/engines/memory/primitives.rb,
lib/arel/algebra/attributes/attribute.rb

Defined Under Namespace

Modules: Congruence, Expressions, Orderings, Predications, Transformations, Types

Instance Method Summary collapse

Methods included from Types

#type_cast, #type_cast_to_numeric, #typecast_error

Methods included from Orderings

#asc, #desc

Methods included from Expressions

#average, #count, #maximum, #minimum, #sum

Methods included from Predications

#eq, #eq_all, #eq_any, #gt, #gt_all, #gt_any, #gteq, #gteq_all, #gteq_any, #in, #in_all, #in_any, #lt, #lt_all, #lt_any, #lteq, #lteq_all, #lteq_any, #matches, #matches_all, #matches_any, #not_eq, #not_eq_all, #not_eq_any, #not_in, #not_in_all, #not_in_any, #not_matches, #not_matches_all, #not_matches_any

Methods included from Congruence

#/, #descends_from?, #find_correlate_in, #history, #join?, #original_attribute, #original_relation, #root

Methods included from Transformations

#as, #bind, #hash, included, #to_attribute

Constructor Details

#initialize(relation, name, options = {}) ⇒ Attribute

Returns a new instance of Attribute.



10
11
12
# File 'lib/arel/algebra/attributes/attribute.rb', line 10

def initialize(relation, name, options = {})
  @relation, @name, @alias, @ancestor = relation, name, options[:alias], options[:ancestor]
end

Instance Method Details

#aggregation?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/arel/algebra/attributes/attribute.rb', line 18

def aggregation?
  false
end

#columnObject



15
16
17
# File 'lib/arel/engines/sql/primitives.rb', line 15

def column
  original_relation.column_for(self)
end

#eval(row) ⇒ Object



3
4
5
# File 'lib/arel/engines/memory/primitives.rb', line 3

def eval(row)
  row[self]
end

#format(object) ⇒ Object



19
20
21
# File 'lib/arel/engines/sql/primitives.rb', line 19

def format(object)
  object.to_sql(Sql::Attribute.new(self))
end

#inspectObject



22
23
24
# File 'lib/arel/algebra/attributes/attribute.rb', line 22

def inspect
  "<Attribute #{name}>"
end

#named?(hypothetical_name) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/arel/algebra/attributes/attribute.rb', line 14

def named?(hypothetical_name)
  (@alias || name).to_s == hypothetical_name.to_s
end

#to_sql(formatter = Sql::WhereCondition.new(relation)) ⇒ Object



23
24
25
# File 'lib/arel/engines/sql/primitives.rb', line 23

def to_sql(formatter = Sql::WhereCondition.new(relation))
  formatter.attribute self
end