Module: Axn::Internal::RenderedText

Defined in:
lib/axn/exceptions.rb

Overview

A caller-supplied value written into one of this file's messages, whatever it turns out to be.

Text.renderable is String-only by contract — it binds String methods, so anything else is a TypeError from the message path itself — and the exceptions here are PUBLIC classes whose kwargs a caller fills in. Axn::Tools::InvalidContract.new(tool: :foo, …) is the shape that proves it: a Symbol naming the tool is the obvious thing to pass, and it must render as foo rather than as an error about rendering.

So the type is decided by case/when (Module#===, a C-level check that runs none of the value's code) and each branch renders what it can honestly get:

* a String, through the byte renderer, since its bytes are foreign too;
* a Symbol, through its own `to_s` — the one dispatch here that needs no guard, because a Symbol can
carry no override at all (`Symbol.new` is undefined, `allocate` raises, and `:x.singleton_class` is a
TypeError), and then rendered, because a Symbol's bytes can be non-UTF-8 as readily as a String's;
* anything else by its CLASS, which is a legible stand-in and cannot raise. Dispatching `to_s` on an
arbitrary object is what a message path here must never do.

Class Method Summary collapse

Class Method Details

.of(value) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/axn/exceptions.rb', line 78

def self.of(value)
  case value
  when ::String then Text.renderable(value)
  when ::Symbol then Text.renderable(value.to_s)
  else RenderedClassName.of(value)
  end
end