Module: Mensa::Scope

Extended by:
ActiveSupport::Concern
Includes:
Search
Included in:
Base
Defined in:
app/tables/mensa/scope.rb

Overview

scope -> filtered_scope -> ordered_scope -> selected_scope ->

Instance Method Summary collapse

Instance Method Details

#filtered_scopeObject

Returns the scope, but filtered



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/tables/mensa/scope.rb', line 13

def filtered_scope
  return @filtered_scope if @filtered_scope

  @filtered_scope = scope
  @filtered_scope = search(@filtered_scope, params[:query]) if params[:query].present?

  # Use inject
  active_filters.each do |filter|
    @filtered_scope = filter.filter_scope(@filtered_scope)
  end

  @filtered_scope
end

#ordered_scopeObject

Returns the filtered_columns, but ordered, we always reorder, scope shouldn’t include ordering



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/tables/mensa/scope.rb', line 28

def ordered_scope
  return @ordered_scope if @ordered_scope

  @ordered_scope = filtered_scope
  @ordered_scope = if effective_order.present?
    @ordered_scope.reorder(effective_order)
  elsif search_order_clause.present?
    @ordered_scope.reorder(Arel.sql(search_order_clause))
  else
    @ordered_scope.reorder(nil)
  end

  @ordered_scope
end

#paged_scopeObject



53
54
55
56
# File 'app/tables/mensa/scope.rb', line 53

def paged_scope
  pagy_object
  @records
end

#pagy_detailsObject



58
59
60
61
# File 'app/tables/mensa/scope.rb', line 58

def pagy_details
  pagy_object
  @pagy_details
end

#selected_scopeObject

Return the ordered_scope, but with only the columns selected



44
45
46
47
48
49
50
51
# File 'app/tables/mensa/scope.rb', line 44

def selected_scope
  return @selected_scope if @selected_scope

  @selected_scope = ordered_scope
  @selected_scope = @selected_scope.select([:id] + columns.filter_map(&:attribute))

  @selected_scope
end