Class: Component::ResourceTable

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#perform

Constructor Details

#initialize(*args) ⇒ ResourceTable

Returns a new instance of ResourceTable.



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

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.



3
4
5
# File 'app/components/component/resource_table.rb', line 3

def resource
  @resource
end

Instance Method Details

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



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

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

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



12
13
14
15
16
# File 'app/components/component/resource_table.rb', line 12

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



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

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

#timestamps(options = {}) ⇒ Object



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

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