Class: EasyTable::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/easy_table/base.rb

Defined Under Namespace

Classes: NilModelClass

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(items, options = {}) ⇒ Base

options:

model_class: the class of the model, used for i18n, using with the human_attribute_name


10
11
12
13
14
15
16
# File 'lib/easy_table/base.rb', line 10

def initialize(items, options = {})
  @items          = items
  @options        = options
  @columns        = []
  @action_columns = []
  process_options
end

Instance Attribute Details

#action_columnsObject (readonly)

Returns the value of attribute action_columns.



3
4
5
# File 'lib/easy_table/base.rb', line 3

def action_columns
  @action_columns
end

#columnsObject (readonly)

Returns the value of attribute columns.



3
4
5
# File 'lib/easy_table/base.rb', line 3

def columns
  @columns
end

#itemsObject (readonly)

Returns the value of attribute items.



3
4
5
# File 'lib/easy_table/base.rb', line 3

def items
  @items
end

#model_classObject (readonly)

Returns the value of attribute model_class.



3
4
5
# File 'lib/easy_table/base.rb', line 3

def model_class
  @model_class
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/easy_table/base.rb', line 3

def options
  @options
end

#presenterObject

Returns the value of attribute presenter.



4
5
6
# File 'lib/easy_table/base.rb', line 4

def presenter
  @presenter
end

Instance Method Details

#action(&block) ⇒ Object



26
27
28
# File 'lib/easy_table/base.rb', line 26

def action(&block)
  @action_columns << ActionColumn.new("", {}, &block)
end

#all_columnsObject



30
31
32
# File 'lib/easy_table/base.rb', line 30

def all_columns
  @all_columns ||= (columns + action_columns)
end

#process_optionsObject



34
35
36
# File 'lib/easy_table/base.rb', line 34

def process_options
  @model_class = options[:model_class] || NilModelClass.instance
end

#td(name, options = {}, &block) ⇒ Object



22
23
24
# File 'lib/easy_table/base.rb', line 22

def td(name, options = {}, &block)
  @columns << Column.new(name, options, &block)
end

#tds(*names) ⇒ Object



18
19
20
# File 'lib/easy_table/base.rb', line 18

def tds(*names)
  names.each { |name| td(name) }
end