Class: WindowExpression

Inherits:
Expression show all
Defined in:
lib/eno.rb

Instance Attribute Summary

Attributes inherited from Expression

#members, #props

Instance Method Summary collapse

Methods inherited from Expression

#!=, #!@, #%, #&, #*, #+, #-, #/, #<, #<=, #==, #>, #>=, #as, #desc, #inner_join, #join, #not_null?, #null?, #over, quote, #|

Constructor Details

#initialize(&block) ⇒ WindowExpression

Returns a new instance of WindowExpression.



184
185
186
# File 'lib/eno.rb', line 184

def initialize(&block)
  instance_eval(&block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym) ⇒ Object



223
224
225
226
# File 'lib/eno.rb', line 223

def method_missing(sym)
  super if sym == :to_hash
  Identifier.new(sym)
end

Instance Method Details

#_order_by_clauseObject



213
214
215
216
# File 'lib/eno.rb', line 213

def _order_by_clause
  return nil unless @order_by
  "order by %s " % @order_by.map { |e| Expression.quote(e) }.join(', ')
end

#_partition_by_clauseObject



208
209
210
211
# File 'lib/eno.rb', line 208

def _partition_by_clause
  return nil unless @partition_by
  "partition by %s " % @partition_by.map { |e| Expression.quote(e) }.join(', ')
end

#_range_clauseObject



218
219
220
221
# File 'lib/eno.rb', line 218

def _range_clause
  return nil unless @range
  "range #{@range} "
end

#order_by(*args) ⇒ Object



192
193
194
# File 'lib/eno.rb', line 192

def order_by(*args)
  @order_by = args
end

#partition_by(*args) ⇒ Object



188
189
190
# File 'lib/eno.rb', line 188

def partition_by(*args)
  @partition_by = args
end

#range_unboundedObject



196
197
198
# File 'lib/eno.rb', line 196

def range_unbounded
  @range = 'between unbounded preceding and unbounded following'
end

#to_sqlObject



200
201
202
203
204
205
206
# File 'lib/eno.rb', line 200

def to_sql
  "(%s)" % [
    _partition_by_clause,
    _order_by_clause,
    _range_clause
  ].join.strip
end