Class: BaseCell
- Inherits:
-
Cell::ViewModel
- Object
- Cell::ViewModel
- BaseCell
show all
- Defined in:
- lib/bootstrap-cells/cells/base_cell.rb
Direct Known Subclasses
AlertCell, ButtonCell, CardCell, ColumnCell, FieldCell, FieldsForCell, KvHorizontalCell, KvVerticalCell, ModalCell, PagesCell, TableCell, TabsCell
Instance Method Summary
collapse
Instance Method Details
#c(*class_list) ⇒ Object
6
7
8
|
# File 'lib/bootstrap-cells/cells/base_cell.rb', line 6
def c(*class_list)
class_list.flatten.compact.uniq.map(&:to_s).map(&:strip).join(' ').strip
end
|
#fetch_errors(object, field) ⇒ Object
31
32
33
34
35
36
37
38
|
# File 'lib/bootstrap-cells/cells/base_cell.rb', line 31
def fetch_errors(object, field)
field = field.to_s
return nil unless object.try(:errors)
errors = object.errors[field]
errors = object.errors[field.remove('_id')] unless errors.any?
return nil unless errors.any?
errors.join('; ')
end
|
#merge_props(from:, to:) ⇒ Object
10
11
12
13
14
15
16
|
# File 'lib/bootstrap-cells/cells/base_cell.rb', line 10
def merge_props(from:, to:)
from ||= {}
to ||= {}
from = from.deep_symbolize_keys
to = to.deep_symbolize_keys
from.deep_merge(to) { |k, o, n| k == :class ? c(n, o) : n }
end
|
#render_attribute_path(path, object) ⇒ Object
27
28
29
|
# File 'lib/bootstrap-cells/cells/base_cell.rb', line 27
def render_attribute_path(path, object)
path&.to_s&.split('.')&.inject(object, :try)&.to_s
end
|
#render_option(option) ⇒ Object
22
23
24
25
|
# File 'lib/bootstrap-cells/cells/base_cell.rb', line 22
def render_option(option)
return nil unless renderable?(option)
options[option].call
end
|
#renderable?(option) ⇒ Boolean
18
19
20
|
# File 'lib/bootstrap-cells/cells/base_cell.rb', line 18
def renderable?(option)
options[option].respond_to?(:call)
end
|
#titleized_attribute_path(attribute) ⇒ Object
40
41
42
|
# File 'lib/bootstrap-cells/cells/base_cell.rb', line 40
def titleized_attribute_path(attribute)
attribute.to_s.split('.').map(&:titleize).join(' ')
end
|