Class: Elements::Table
- Inherits:
-
Object
- Object
- Elements::Table
- Includes:
- ActionView::Helpers::TagHelper, Helpers::Paginate
- Defined in:
- lib/rails_table_for/elements/table.rb
Instance Attribute Summary collapse
-
#columns ⇒ Object
writeonly
Sets the attribute columns.
-
#output_buffer ⇒ Object
Returns the value of attribute output_buffer.
-
#page_size ⇒ Object
writeonly
Sets the attribute page_size.
-
#record_count ⇒ Object
writeonly
Sets the attribute record_count.
-
#records ⇒ Object
writeonly
Sets the attribute records.
-
#request_params ⇒ Object
writeonly
Sets the attribute request_params.
-
#request_path ⇒ Object
writeonly
Sets the attribute request_path.
Instance Method Summary collapse
- #column(field = nil, **options, &block) ⇒ Object
-
#initialize(records, **options) ⇒ Table
constructor
A new instance of Table.
- #to_s ⇒ Object
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, **) @records = records @record_count = records.count @columns = [] [:columns]&.each { |field| column(field) } @page_size = [:page_size] @request_path = [:request_path] @request_params = [:request_params] end |
Instance Attribute Details
#columns=(value) ⇒ Object
Sets the attribute columns
12 13 14 |
# File 'lib/rails_table_for/elements/table.rb', line 12 def columns=(value) @columns = value end |
#output_buffer ⇒ Object
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
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
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
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
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
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, **, &block) if block_given? columns << BlockColumn.new(block, ) elsif field columns << FieldColumn.new(field, ) else raise 'Must provide either field or block' end end |
#to_s ⇒ Object
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 |