Class: Squeel::Nodes::Function

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

Overview

A node that represents an SQL function call

Direct Known Subclasses

Operation

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Operators

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

Constructor Details

#initialize(name, args) ⇒ Function

Create a node representing an SQL Function with the given name and arguments

Parameters:

  • name (Symbol)

    The function name

  • args (Array)

    The array of arguments to pass to the function.



36
37
38
# File 'lib/squeel/nodes/function.rb', line 36

def initialize(name, args)
  @name, @args = name, args
end

Instance Attribute Details

#aliasString, NilClass (readonly)

Returns:

  • (String)

    The SQL function’s alias

  • (NilClass)

    If no alias



31
32
33
# File 'lib/squeel/nodes/function.rb', line 31

def alias
  @alias
end

#argsArray (readonly)

Returns The arguments to be passed to the SQL function.

Returns:

  • (Array)

    The arguments to be passed to the SQL function



27
28
29
# File 'lib/squeel/nodes/function.rb', line 27

def args
  @args
end

#nameSymbol (readonly)

Returns The name of the SQL function to be called.

Returns:

  • (Symbol)

    The name of the SQL function to be called



24
25
26
# File 'lib/squeel/nodes/function.rb', line 24

def name
  @name
end

Instance Method Details

#as(alias_name) ⇒ Function

Set an alias for the function

Parameters:

  • The (String, Symbol)

    alias name

Returns:

  • (Function)

    This function with the new alias value.



43
44
45
46
# File 'lib/squeel/nodes/function.rb', line 43

def as(alias_name)
  @alias = alias_name.to_s
  self
end

#ascObject



48
49
50
# File 'lib/squeel/nodes/function.rb', line 48

def asc
  Order.new self, 1
end

#descObject



52
53
54
# File 'lib/squeel/nodes/function.rb', line 52

def desc
  Order.new self, -1
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



60
61
62
# File 'lib/squeel/nodes/function.rb', line 60

def to_sym
  nil
end