Class: Component::CollectionTable

Inherits:
Base
  • Object
show all
Includes:
AwesomeNestedSetConcern
Defined in:
app/components/component/collection_table.rb

Defined Under Namespace

Modules: AwesomeNestedSetConcern

Constant Summary collapse

SIZE_MAP =
{
  default: nil,
  small:   :sm
}

Instance Method Summary collapse

Methods included from AwesomeNestedSetConcern

#awesome_nested_set_actions

Methods inherited from Base

#perform

Constructor Details

#initialize(*args) ⇒ CollectionTable

Returns a new instance of CollectionTable.



10
11
12
13
14
15
# File 'app/components/component/collection_table.rb', line 10

def initialize(*args)
  super
  @columns        = {}
  @collection     = @options.delete(:collection)
  @resource_class = @options.delete(:resource_class) || @collection.first.class
end

Instance Method Details

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



32
33
34
35
# File 'app/components/component/collection_table.rb', line 32

def association(name, options = {}, &block)
  options.reverse_merge!(render_as: :association)
  column(name, options, &block)
end

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



17
18
19
20
21
# File 'app/components/component/collection_table.rb', line 17

def column(name, options = {}, &block)
  options.reverse_merge!(render_as: :default)
  options.reverse_merge!(block: block) if block_given?
  @columns[name] = options
end

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



22
23
24
25
# File 'app/components/component/collection_table.rb', line 22

def timestamp(name, options = {}, &block)
  options.reverse_merge!(render_as: :timestamp, format: nil)
  column(name, options, &block)
end

#timestamps(options = {}) ⇒ Object



27
28
29
30
# File 'app/components/component/collection_table.rb', line 27

def timestamps(options = {})
  timestamp(:created_at, options)
  timestamp(:updated_at, options)
end