Class: Elements::Table

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::TagHelper, Helpers::Paginate
Defined in:
lib/rails_table_for/elements/table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(records, **options) ⇒ Table

Returns a new instance of Table.



16
17
18
19
20
21
22
23
24
# File 'lib/rails_table_for/elements/table.rb', line 16

def initialize(records, **options)
  @records = records
  @record_count = records.count
  @columns = []
  options[:columns]&.each { |field| column(field) }
  @page_size = options[:page_size]
  @request_path = options[:request_path]
  @request_params = options[:request_params]
end

Instance Attribute Details

#columns=(value) ⇒ Object

Sets the attribute columns

Parameters:

  • value

    the value to set the attribute columns to.



12
13
14
# File 'lib/rails_table_for/elements/table.rb', line 12

def columns=(value)
  @columns = value
end

#output_bufferObject

Returns the value of attribute output_buffer.



12
13
14
# File 'lib/rails_table_for/elements/table.rb', line 12

def output_buffer
  @output_buffer
end

#page_size=(value) ⇒ Object

Sets the attribute page_size

Parameters:

  • value

    the value to set the attribute page_size to.



12
13
14
# File 'lib/rails_table_for/elements/table.rb', line 12

def page_size=(value)
  @page_size = value
end

#record_count=(value) ⇒ Object

Sets the attribute record_count

Parameters:

  • value

    the value to set the attribute record_count to.



12
13
14
# File 'lib/rails_table_for/elements/table.rb', line 12

def record_count=(value)
  @record_count = value
end

#records=(value) ⇒ Object

Sets the attribute records

Parameters:

  • value

    the value to set the attribute records to.



12
13
14
# File 'lib/rails_table_for/elements/table.rb', line 12

def records=(value)
  @records = value
end

#request_params=(value) ⇒ Object

Sets the attribute request_params

Parameters:

  • value

    the value to set the attribute request_params to.



12
13
14
# File 'lib/rails_table_for/elements/table.rb', line 12

def request_params=(value)
  @request_params = value
end

#request_path=(value) ⇒ Object

Sets the attribute request_path

Parameters:

  • value

    the value to set the attribute request_path to.



12
13
14
# File 'lib/rails_table_for/elements/table.rb', line 12

def request_path=(value)
  @request_path = value
end

Instance Method Details

#column(field = nil, **options, &block) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/rails_table_for/elements/table.rb', line 26

def column(field = nil, **options, &block)
  if block_given?
    columns << BlockColumn.new(block, options)
  elsif field
    columns << FieldColumn.new(field, options)
  else
    raise 'Must provide either field or block'
  end
end

#to_sObject



36
37
38
39
40
41
# File 'lib/rails_table_for/elements/table.rb', line 36

def to_s
  return '' if record_count.zero?
  return '' if columns.nil? || columns.empty?

  draw
end