Class: Katalyst::Tables::Collection::Array

Inherits:
Object
  • Object
show all
Includes:
Core
Defined in:
app/models/katalyst/tables/collection/array.rb

Overview

Entry point for creating a collection from an array for use with table components.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Core

#apply, #filter, #filtered?, #filters, #initialize, #searchable?, #sortable?

Methods included from HasParams

#to_params

Class Method Details

.with_params(params) ⇒ Object



10
11
12
# File 'app/models/katalyst/tables/collection/array.rb', line 10

def self.with_params(params)
  new.with_params(params)
end

Instance Method Details

#inspectObject



31
32
33
# File 'app/models/katalyst/tables/collection/array.rb', line 31

def inspect
  "#<#{self.class.name} @attributes=#{attributes.inspect} @model_name=\"#{model_name}\" @count=#{items&.count}>"
end

#modelObject



14
15
16
# File 'app/models/katalyst/tables/collection/array.rb', line 14

def model
  items.first&.class || ActiveRecord::Base
end

#model_nameObject



18
19
20
# File 'app/models/katalyst/tables/collection/array.rb', line 18

def model_name
  @model_name ||= items.first&.model_name || ActiveModel::Name.new(Object, nil, "record")
end

#with_params(params) ⇒ Object



22
23
24
25
26
27
28
29
# File 'app/models/katalyst/tables/collection/array.rb', line 22

def with_params(params)
  # test support
  params = ActionController::Parameters.new(params) unless params.is_a?(ActionController::Parameters)

  self.attributes = params.permit(self.class.permitted_params)

  self
end