Module: ActiveRecordExtended::QueryMethods::Window

Defined in:
lib/active_record_extended/query_methods/window.rb

Defined Under Namespace

Classes: DefineWindowChain, WindowSelectBuilder

Instance Method Summary collapse

Instance Method Details

#build_windows(arel) ⇒ Object


82
83
84
85
86
87
88
# File 'lib/active_record_extended/query_methods/window.rb', line 82

def build_windows(arel)
  window_values.each do |window_value|
    window = arel.window(window_value[:window_name])
    window = window.partition(window_value[:partition_by]) if window_value[:partition_by].present?
    window.order(window_value[:order_by])                  if window_value[:order_by]
  end
end

#define_window(name) ⇒ Object


62
63
64
# File 'lib/active_record_extended/query_methods/window.rb', line 62

def define_window(name)
  spawn.define_window!(name)
end

#define_window!(name) ⇒ Object


66
67
68
# File 'lib/active_record_extended/query_methods/window.rb', line 66

def define_window!(name)
  DefineWindowChain.new(self, name)
end

#select_window(window_function, *args, over:, as: nil) ⇒ Object


70
71
72
# File 'lib/active_record_extended/query_methods/window.rb', line 70

def select_window(window_function, *args, over:, as: nil)
  spawn.select_window!(window_function, args, over: over, as: as)
end

#select_window!(window_function, *args, over:, as: nil) ⇒ Object


74
75
76
77
78
79
80
# File 'lib/active_record_extended/query_methods/window.rb', line 74

def select_window!(window_function, *args, over:, as: nil)
  args.flatten!
  args.compact!

  select_statement = WindowSelectBuilder.new(window_function, args, over).build_select(as)
  _select!(select_statement)
end

#window_valuesObject


46
47
48
# File 'lib/active_record_extended/query_methods/window.rb', line 46

def window_values
  @values.fetch(:window, [])
end

#window_values!Object


50
51
52
# File 'lib/active_record_extended/query_methods/window.rb', line 50

def window_values!
  @values[:window] ||= []
end

#window_values=(*values) ⇒ Object


58
59
60
# File 'lib/active_record_extended/query_methods/window.rb', line 58

def window_values=(*values)
  @values[:window] = values.flatten(1)
end

#window_values?Boolean

Returns:

  • (Boolean)

54
55
56
# File 'lib/active_record_extended/query_methods/window.rb', line 54

def window_values?
  !window_values.empty?
end