Module: Acta::Upcaster::ClassMethods
- Defined in:
- lib/acta/upcaster.rb
Instance Method Summary collapse
- #upcaster_registrations ⇒ Object
-
#upcasts(event_type, from:, to:, &block) ⇒ Object
Declare a transform.
Instance Method Details
#upcaster_registrations ⇒ Object
63 64 65 |
# File 'lib/acta/upcaster.rb', line 63 def upcaster_registrations @upcaster_registrations ||= [] end |
#upcasts(event_type, from:, to:, &block) ⇒ Object
Declare a transform. ‘from` and `to` are integer schema versions on the same event type; `to` must be >= `from`. The block receives an upcast-shaped record and the per-replay context, and must return either a single upcasted record, an array (1-to-many — each branch continues chaining independently), `nil`/`[]` (drop on replay), or call `context.fail_replay!(reason)`.
54 55 56 57 58 59 60 61 |
# File 'lib/acta/upcaster.rb', line 54 def upcasts(event_type, from:, to:, &block) raise UpcasterRegistryError, "from must be an Integer" unless from.is_a?(Integer) raise UpcasterRegistryError, "to must be an Integer" unless to.is_a?(Integer) raise UpcasterRegistryError, "to (#{to}) must be >= from (#{from})" if to < from raise UpcasterRegistryError, "block required for upcasts(#{event_type.inspect}, from: #{from}, to: #{to})" unless block upcaster_registrations << { event_type: event_type.to_s, from:, to:, block: } end |