Class: Arel::Nodes::Window

Inherits:
Node
  • Object
show all
Defined in:
lib/arel/nodes/window.rb

Direct Known Subclasses

NamedWindow

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#_caller, #and, #each, #not, #or, #to_sql

Methods included from FactoryMethods

#create_and, #create_false, #create_join, #create_on, #create_string_join, #create_table_alias, #create_true, #grouping, #lower

Constructor Details

#initializeWindow

Returns a new instance of Window.



6
7
8
9
10
# File 'lib/arel/nodes/window.rb', line 6

def initialize
  @orders = []
  @partitions = []
  @framing = nil
end

Instance Attribute Details

#framingObject

Returns the value of attribute framing.



4
5
6
# File 'lib/arel/nodes/window.rb', line 4

def framing
  @framing
end

#ordersObject

Returns the value of attribute orders.



4
5
6
# File 'lib/arel/nodes/window.rb', line 4

def orders
  @orders
end

#partitionsObject

Returns the value of attribute partitions.



4
5
6
# File 'lib/arel/nodes/window.rb', line 4

def partitions
  @partitions
end

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


57
58
59
60
61
62
# File 'lib/arel/nodes/window.rb', line 57

def eql? other
  self.class == other.class &&
    self.orders == other.orders &&
    self.framing == other.framing &&
    self.partitions == other.partitions
end

#frame(expr) ⇒ Object



28
29
30
# File 'lib/arel/nodes/window.rb', line 28

def frame(expr)
  @framing = expr
end

#hashObject



53
54
55
# File 'lib/arel/nodes/window.rb', line 53

def hash
  [@orders, @framing].hash
end

#initialize_copy(other) ⇒ Object



48
49
50
51
# File 'lib/arel/nodes/window.rb', line 48

def initialize_copy other
  super
  @orders = @orders.map { |x| x.clone }
end

#order(*expr) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/arel/nodes/window.rb', line 12

def order *expr
  # FIXME: We SHOULD NOT be converting these to SqlLiteral automatically
  @orders.concat expr.map { |x|
    String === x || Symbol === x ? Nodes::SqlLiteral.new(x.to_s) : x
  }
  self
end

#partition(*expr) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/arel/nodes/window.rb', line 20

def partition *expr
  # FIXME: We SHOULD NOT be converting these to SqlLiteral automatically
  @partitions.concat expr.map { |x|
    String === x || Symbol === x ? Nodes::SqlLiteral.new(x.to_s) : x
  }
  self
end

#range(expr = nil) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/arel/nodes/window.rb', line 40

def range(expr = nil)
  if @framing
    Range.new(expr)
  else
    frame(Range.new(expr))
  end
end

#rows(expr = nil) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/arel/nodes/window.rb', line 32

def rows(expr = nil)
  if @framing
    Rows.new(expr)
  else
    frame(Rows.new(expr))
  end
end