Class: Telm::Core::Rendering

Inherits:
Object
  • Object
show all
Defined in:
lib/telm/core/rendering.rb

Overview

Maps (resource, column, record) to a display-type Cell. Pure data out — the view layer decides markup. Kinds:

:redacted, :null, :empty_string, :boolean, :enum, :datetime, :date,
:json, :binary, :number, :string, :belongs_to

Defined Under Namespace

Classes: Cell

Constant Summary collapse

TEXT_TRUNCATE_AT =
200

Instance Method Summary collapse

Constructor Details

#initialize(schema: Telm.schema, redaction: Telm.redaction) ⇒ Rendering

Returns a new instance of Rendering.



19
20
21
22
# File 'lib/telm/core/rendering.rb', line 19

def initialize(schema: Telm.schema, redaction: Telm.redaction)
  @schema = schema
  @redaction = redaction
end

Instance Method Details

#cell(resource, column, record) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/telm/core/rendering.rb', line 24

def cell(resource, column, record)
  return Cell.new(kind: :redacted) if @redaction.redact?(resource.table_name, column.name)

  value = record[column.name]
  return Cell.new(kind: :null) if value.nil?

  belongs_to_cell(resource, column, record, value) ||
    enum_cell(resource, column, value) ||
    typed_cell(column, value)
end