class Proforma::HtmlRenderer::ObjectWriter

Each object should have its own ERB template. This class understands the connection of objects and templates and knows how to render the template for the respective object passed in.

Attributes

names_by_class[R]
writer[R]

Public Class Methods

new(names_by_class: {}, writer: Writer.new) click to toggle source
# File lib/proforma/html_renderer/object_writer.rb, line 20
def initialize(names_by_class: {}, writer: Writer.new)
  @names_by_class = names_by_class
  @writer         = writer
end

Public Instance Methods

render(object, options = {}) click to toggle source
# File lib/proforma/html_renderer/object_writer.rb, line 25
def render(object, options = {})
  writer.render(
    resolve_name(object),
    object: object,
    options: options
  )
end

Private Instance Methods

resolve_name(object) click to toggle source
# File lib/proforma/html_renderer/object_writer.rb, line 35
def resolve_name(object)
  names_by_class[object.class].tap do |name|
    raise ArgumentError, "object cannot be rendered: #{object.class}" unless name
  end
end