Class: Effective::TableRow

Inherits:
Object
  • Object
show all
Defined in:
app/models/effective/table_row.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options, builder:) ⇒ TableRow

So this takes in the options for an entire form group.



11
12
13
14
15
16
17
# File 'app/models/effective/table_row.rb', line 11

def initialize(name, options, builder:)
  @builder = builder
  @template = builder.template

  @name = name
  @options = options
end

Instance Attribute Details

#builder ⇒ Object

Returns the value of attribute builder.



5
6
7
# File 'app/models/effective/table_row.rb', line 5

def builder
  @builder
end

#name ⇒ Object

Returns the value of attribute name.



5
6
7
# File 'app/models/effective/table_row.rb', line 5

def name
  @name
end

#options ⇒ Object

Returns the value of attribute options.



5
6
7
# File 'app/models/effective/table_row.rb', line 5

def options
  @options
end

#template ⇒ Object

Returns the value of attribute template.



5
6
7
# File 'app/models/effective/table_row.rb', line 5

def template
  @template
end

Instance Method Details

#content ⇒ Object

Intended for override



24
25
26
# File 'app/models/effective/table_row.rb', line 24

def content
  value
end

#controller_namespace ⇒ Object



19
20
21
# File 'app/models/effective/table_row.rb', line 19

def controller_namespace
  Effective::Resource.new(template.controller.controller_path).namespace
end

#label ⇒ Object

Humanized label or the label from form



36
37
38
39
40
41
# File 'app/models/effective/table_row.rb', line 36

def label
  text = options[:label] || builder.human_attribute_name(name)
  prefix = builder.options[:prefix]

  [*prefix, text].join(': ')
end

#to_html(&block) ⇒ Object

Render method



29
30
31
32
33
# File 'app/models/effective/table_row.rb', line 29

def to_html(&block)
  (:tr) do
    (:td, label) + (:td, content.presence || '-')
  end
end

#value ⇒ Object

Value from resource



44
45
46
# File 'app/models/effective/table_row.rb', line 44

def value
  options[:value] || builder.value(name)
end