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

Extended by:
ActiveSupport::Concern
Includes:
ActiveModel::Attributes, ActiveModel::Dirty, ActiveModel::Model, 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



89
90
91
92
93
94
95
96
# File 'app/models/concerns/katalyst/tables/collection/core.rb', line 89

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

#filterObject



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

def filter
  # no-op by default
end

#filtered?Boolean

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

Returns:

  • (Boolean)


75
76
77
# File 'app/models/concerns/katalyst/tables/collection/core.rb', line 75

def filtered?
  filters.any?
end

#filtersObject



102
103
104
105
106
# File 'app/models/concerns/katalyst/tables/collection/core.rb', line 102

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

#initialize(**options) ⇒ Object



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

def initialize(**options)
  super

  clear_changes_information
end

#modelObject



108
109
110
111
112
113
114
# File 'app/models/concerns/katalyst/tables/collection/core.rb', line 108

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)


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

def searchable?
  false
end

#sortable?Boolean

Collections that do not include Sorting are never sortable.

Returns:

  • (Boolean)


80
81
82
# File 'app/models/concerns/katalyst/tables/collection/core.rb', line 80

def sortable?
  false
end