Class: Component::ResourceTable

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

Defined Under Namespace

Modules: BooleanConcern

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BooleanConcern

#boolean

Methods inherited from Base

#perform

Constructor Details

#initialize(*args) ⇒ ResourceTable


7
8
9
10
11
12
# File 'app/components/component/resource_table.rb', line 7

def initialize(*args)
  super
  @rows           = {}
  @resource       = @options.delete(:resource)
  @resource_class = @resource.class
end

Instance Attribute Details

#resourceObject (readonly)

Returns the value of attribute resource


5
6
7
# File 'app/components/component/resource_table.rb', line 5

def resource
  @resource
end

Instance Method Details

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


34
35
36
37
# File 'app/components/component/resource_table.rb', line 34

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

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


20
21
22
# File 'app/components/component/resource_table.rb', line 20

def id(options = {}, &block)
  row(:id, options, &block)
end

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


14
15
16
17
18
# File 'app/components/component/resource_table.rb', line 14

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

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


24
25
26
27
# File 'app/components/component/resource_table.rb', line 24

def timestamp(name, options = {}, &block)
  options.reverse_merge!(render_as: :timestamp, format: Rails::AddOns::Configuration.table_default_timestamp_format)
  row(name, options, &block)
end

#timestamps(options = {}) ⇒ Object


29
30
31
32
# File 'app/components/component/resource_table.rb', line 29

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