Class: GridTable::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/grid_table/table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTable

Returns a new instance of Table.



4
5
6
# File 'lib/grid_table/table.rb', line 4

def initialize
  @controls = []
end

Instance Attribute Details

#recordsObject (readonly)

Returns the value of attribute records.



2
3
4
# File 'lib/grid_table/table.rb', line 2

def records
  @records
end

#total_rowsObject (readonly)

Returns the value of attribute total_rows.



2
3
4
# File 'lib/grid_table/table.rb', line 2

def total_rows
  @total_rows
end

Instance Method Details

#add_control(model, attribute, options) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/grid_table/table.rb', line 8

def add_control(model, attribute, options)
  @controls << GridTable::Control.new(
    {
      model: model.name.underscore.to_sym,
      attribute: attribute,
      source: options[:source],
      source_class: options[:source_class],
      source_column: options[:source_column],
      filter: options[:filter],
      polymorphic: options[:polymorphic]
    })
end

#populate!(resource, params) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/grid_table/table.rb', line 21

def populate!(resource, params)
  @params   = HashWithIndifferentAccess.new(params)
  @records  = resource

  filter! unless params[:skip_filtering]
  sort! unless params[:skip_sorting]
  @total_rows = @records.size
  page! unless params[:skip_paging]

  @records
end

#strong_paramsObject



33
34
35
36
37
# File 'lib/grid_table/table.rb', line 33

def strong_params
  @controls.inject(common_strong_params) do |all_params, control|
    all_params << control.url_param
  end
end