Class: Hegel::Generator::Mapped

Inherits:
Generator
  • Object
show all
Defined in:
lib/hegel/generator.rb,
sig/hegel.rbs

Overview

Generator#map's result. A private implementation detail of #map, not part of this library's public generator vocabulary (unlike the five under Hegel::Generators), so it lives here rather than in generators.rb.

Instance Method Summary collapse

Constructor Details

#initialize(source, block) ⇒ Mapped

Returns a new instance of Mapped.

Parameters:



41
42
43
44
45
# File 'lib/hegel/generator.rb', line 41

def initialize(source, block)
  super()
  @source = source
  @block = block
end

Instance Method Details

#do_draw(tc) ⇒ Object

Parameters:

  • tc (Object)

Returns:

  • (Object)


47
48
49
50
51
52
53
54
55
56
57
# File 'lib/hegel/generator.rb', line 47

def do_draw(tc)
  tc.start_span(LibHegel::HEGEL_LABEL_MAPPED)
  @block.call(@source.do_draw(tc))
ensure
  # discard is always false here: a span is only ever marked
  # rejected to ask libhegel to retry it with different data (see
  # Filtered below), and #map has no such retry -- an exception from
  # +block+ or +source+ propagates past this method instead, and the
  # span still has to close on the way out.
  tc.stop_span(discard: false)
end