Module: Katalyst::Tables::Collection::Core

Extended by:
ActiveSupport::Concern
Includes:
ActiveModel::Attributes, ActiveModel::Dirty, ActiveModel::Model, ActiveSupport::Configurable, HasParams, Reducers
Included in:
Array, Base, Filter
Defined in:
app/models/concerns/katalyst/tables/collection/core.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods included from HasParams

#to_params

Instance Method Details

#apply(items) ⇒ Object



75
76
77
78
79
80
81
82
# File 'app/models/concerns/katalyst/tables/collection/core.rb', line 75

def apply(items)
  @unscoped_items = @items = items
  reducers.build do |_|
    filter
    self
  end.call(self)
  self
end

#filterObject



84
85
86
# File 'app/models/concerns/katalyst/tables/collection/core.rb', line 84

def filter
  # no-op by default
end

#filtered?Boolean

Collections are filtered when any parameters have changed from their defaults.

Returns:

  • (Boolean)


61
62
63
# File 'app/models/concerns/katalyst/tables/collection/core.rb', line 61

def filtered?
  filters.any?
end

#filtersObject



88
89
90
91
92
# File 'app/models/concerns/katalyst/tables/collection/core.rb', line 88

def filters
  changes
    .select { |k, _| self.class._default_attributes[k].type.filterable? }
    .transform_values(&:second)
end

#initialize(**options) ⇒ Object



54
55
56
57
58
# File 'app/models/concerns/katalyst/tables/collection/core.rb', line 54

def initialize(**options)
  super

  clear_changes_information
end

#modelObject



94
95
96
97
98
99
100
# File 'app/models/concerns/katalyst/tables/collection/core.rb', line 94

def model
  if items < ActiveRecord::Base
    items
  else
    items.model
  end
end

#searchable?Boolean

Collections that do not include Query are never searchable.

Returns:

  • (Boolean)


71
72
73
# File 'app/models/concerns/katalyst/tables/collection/core.rb', line 71

def searchable?
  false
end

#sortable?Boolean

Collections that do not include Sorting are never sortable.

Returns:

  • (Boolean)


66
67
68
# File 'app/models/concerns/katalyst/tables/collection/core.rb', line 66

def sortable?
  false
end