Class: Squeel::Nodes::Literal

Inherits:
Object
  • Object
show all
Includes:
Aliasing, Operators, PredicateMethods
Defined in:
lib/squeel/nodes/literal.rb

Overview

Literal nodes are a container for raw SQL.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Aliasing

#as

Methods included from Operators

#*, #+, #-, #/, #op

Constructor Details

#initialize(expr) ⇒ Literal

Returns a new instance of Literal.



15
16
17
# File 'lib/squeel/nodes/literal.rb', line 15

def initialize(expr)
  @expr = expr
end

Instance Attribute Details

#exprObject (readonly)

Returns the value of attribute expr.



13
14
15
# File 'lib/squeel/nodes/literal.rb', line 13

def expr
  @expr
end

Instance Method Details

#ascOrder

Create an ascending Order node with this Literal as its expression

Returns:

  • (Order)

    The new Order node



33
34
35
# File 'lib/squeel/nodes/literal.rb', line 33

def asc
  Order.new self, 1
end

#descOrder

Create a descending Order node with this Literal as its expression

Returns:

  • (Order)

    The new Order node



39
40
41
# File 'lib/squeel/nodes/literal.rb', line 39

def desc
  Order.new self, -1
end

#eql?(other) ⇒ Boolean

Object comparison

Returns:

  • (Boolean)


44
45
46
47
# File 'lib/squeel/nodes/literal.rb', line 44

def eql?(other)
  self.class.eql?(other.class) &&
  self.expr.eql?(other.expr)
end

#hashObject

To support object equality tests



50
51
52
# File 'lib/squeel/nodes/literal.rb', line 50

def hash
  expr.hash
end

#to_sString Also known as: to_str

Returns The Literal’s String equivalent.

Returns:

  • (String)

    The Literal’s String equivalent.



63
64
65
# File 'lib/squeel/nodes/literal.rb', line 63

def to_s
  expr.to_s
end

#to_symNilClass

expand_hash_conditions_for_aggregates assumes our hash keys can be converted to symbols, so this has to be implemented, but it doesn’t really have to do anything useful.

Returns:

  • (NilClass)

    Just to avoid bombing out on expand_hash_conditions_for_aggregates



58
59
60
# File 'lib/squeel/nodes/literal.rb', line 58

def to_sym
  nil
end