Class: TableHelp::AttributesTableFor

Inherits:
Object
  • Object
show all
Defined in:
lib/table_help/attributes_table_for.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource, context, options = {}) ⇒ AttributesTableFor

Returns a new instance of AttributesTableFor.



6
7
8
9
10
11
# File 'lib/table_help/attributes_table_for.rb', line 6

def initialize(resource, context, options = {})
  @resource = resource
  @context  = context
  @options  = default_options.merge(options)
  @rows     = []
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



3
4
5
# File 'lib/table_help/attributes_table_for.rb', line 3

def context
  @context
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/table_help/attributes_table_for.rb', line 3

def options
  @options
end

#resourceObject (readonly)

Returns the value of attribute resource.



3
4
5
# File 'lib/table_help/attributes_table_for.rb', line 3

def resource
  @resource
end

#rowsObject (readonly)

Returns the value of attribute rows.



3
4
5
# File 'lib/table_help/attributes_table_for.rb', line 3

def rows
  @rows
end

Instance Method Details

#row(name = nil, method_name = nil, &block) ⇒ Object



13
14
15
16
17
18
# File 'lib/table_help/attributes_table_for.rb', line 13

def row(name = nil, method_name = nil, &block)
  rows << [
    Formatter.format_attribute_name(name, resource),
    Strategy.new(name, block_given? ? block : method_name),
  ]
end

#to_htmlObject



20
21
22
23
# File 'lib/table_help/attributes_table_for.rb', line 20

def to_html
  return if resource.nil?
  tag.table(tbody, options)
end