Class: TableGo::Table
- Inherits:
-
Object
- Object
- TableGo::Table
- Defined in:
- lib/table_go/table.rb
Instance Attribute Summary collapse
-
#collection ⇒ Object
Returns the value of attribute collection.
-
#columns ⇒ Object
Returns the value of attribute columns.
-
#model_klass ⇒ Object
Returns the value of attribute model_klass.
Instance Method Summary collapse
- #apply_options!(options) ⇒ Object
- #attribute_names_from_model_klass ⇒ Object
- #column(name, options = {}, &block) ⇒ Object
- #evaluate_dsl!(block) ⇒ Object
-
#initialize(collection, model_klass, options, &block) ⇒ Table
constructor
A new instance of Table.
- #render_rows_only(render_rows_only = nil) ⇒ Object
- #row_html(row_html = nil) ⇒ Object
- #table_html(table_html = nil) ⇒ Object
- #title(title = nil) ⇒ Object
- #without_header(without_header = nil) ⇒ Object
Constructor Details
#initialize(collection, model_klass, options, &block) ⇒ Table
Returns a new instance of Table.
7 8 9 10 11 12 13 |
# File 'lib/table_go/table.rb', line 7 def initialize(collection, model_klass, , &block) @collection = collection @model_klass = model_klass @columns = [] () evaluate_dsl!(block) end |
Instance Attribute Details
#collection ⇒ Object
Returns the value of attribute collection.
4 5 6 |
# File 'lib/table_go/table.rb', line 4 def collection @collection end |
#columns ⇒ Object
Returns the value of attribute columns.
5 6 7 |
# File 'lib/table_go/table.rb', line 5 def columns @columns end |
#model_klass ⇒ Object
Returns the value of attribute model_klass.
4 5 6 |
# File 'lib/table_go/table.rb', line 4 def model_klass @model_klass end |
Instance Method Details
#apply_options!(options) ⇒ Object
35 36 37 |
# File 'lib/table_go/table.rb', line 35 def () .each { |k, v| send(k, v) } end |
#attribute_names_from_model_klass ⇒ Object
31 32 33 |
# File 'lib/table_go/table.rb', line 31 def attribute_names_from_model_klass model_klass.respond_to?(:column_names) ? model_klass.column_names : [] end |
#column(name, options = {}, &block) ⇒ Object
41 42 43 |
# File 'lib/table_go/table.rb', line 41 def column(name, = {}, &block) @columns << Column.new(self, name, , &block) end |
#evaluate_dsl!(block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/table_go/table.rb', line 15 def evaluate_dsl!(block) if block # instance_eval(&block) block.call(self) else attribute_names_from_model_klass.each do |column_name| column(column_name) end end end |
#render_rows_only(render_rows_only = nil) ⇒ Object
60 61 62 63 |
# File 'lib/table_go/table.rb', line 60 def render_rows_only(render_rows_only = nil) @render_rows_only = render_rows_only if render_rows_only @render_rows_only end |
#row_html(row_html = nil) ⇒ Object
55 56 57 58 |
# File 'lib/table_go/table.rb', line 55 def row_html(row_html = nil) @row_html = row_html if row_html @row_html end |
#table_html(table_html = nil) ⇒ Object
50 51 52 53 |
# File 'lib/table_go/table.rb', line 50 def table_html(table_html = nil) @table_html = table_html if table_html @table_html end |
#title(title = nil) ⇒ Object
45 46 47 48 |
# File 'lib/table_go/table.rb', line 45 def title(title = nil) @title = title if title @title end |
#without_header(without_header = nil) ⇒ Object
65 66 67 68 |
# File 'lib/table_go/table.rb', line 65 def without_header(without_header = nil) @without_header = without_header if without_header @without_header end |