Class: TableGo::Table

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options, &block)
  @collection  = collection
  @model_klass = model_klass
  @columns     = []
  apply_options!(options)
  evaluate_dsl!(block)
end

Instance Attribute Details

#collectionObject

Returns the value of attribute collection.



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

def collection
  @collection
end

#columnsObject

Returns the value of attribute columns.



5
6
7
# File 'lib/table_go/table.rb', line 5

def columns
  @columns
end

#model_klassObject

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 apply_options!(options)
  options.each { |k, v| send(k, v) }
end

#attribute_names_from_model_klassObject



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, options = {}, &block)
  @columns << Column.new(self, name, options, &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