Class: Bparity::Recording::Recorder
- Inherits:
-
Object
- Object
- Bparity::Recording::Recorder
- Defined in:
- lib/bparity/recording.rb
Instance Attribute Summary collapse
-
#writer ⇒ Object
readonly
Returns the value of attribute writer.
Instance Method Summary collapse
- #capture(subject, receiver, operation, args, kwargs, block) ⇒ Object
-
#initialize(boundary:, writer:) ⇒ Recorder
constructor
A new instance of Recorder.
- #install! ⇒ Object
Constructor Details
#initialize(boundary:, writer:) ⇒ Recorder
Returns a new instance of Recorder.
292 293 294 295 296 297 |
# File 'lib/bparity/recording.rb', line 292 def initialize(boundary:, writer:) @boundary = boundary @writer = writer @sequence = 0 @canonicalizer = Canonicalizer.new(boundary.canonicalization) end |
Instance Attribute Details
#writer ⇒ Object (readonly)
Returns the value of attribute writer.
290 291 292 |
# File 'lib/bparity/recording.rb', line 290 def writer @writer end |
Instance Method Details
#capture(subject, receiver, operation, args, kwargs, block) ⇒ Object
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
# File 'lib/bparity/recording.rb', line 305 def capture(subject, receiver, operation, args, kwargs, block) projections = subject.return_projections before_args = Serializer.dump(args) yields = [] wrapped = block && proc { |*items| yields << Serializer.dump(items) block.call(*items) } pre_state = project_state(subject, receiver) Context.external_stack << [] outcome = yield(wrapped) serialized = Serializer.dump(outcome, projections:) external_calls = Context.external_stack.pop write(subject, receiver, operation, args, kwargs, before_args, yields, pre_state, block, external_calls, result_value: serialized) outcome rescue Exception => e # rubocop:disable Lint/RescueException -- recording must preserve every observable exception external_calls = Context.external_stack.pop || [] write(subject, receiver, operation, args, kwargs, before_args, yields, pre_state, block, external_calls, error: { "class" => e.class.name, "message" => Bparity.(e), "cause" => e.cause&.class&.name }) raise end |
#install! ⇒ Object
299 300 301 302 303 |
# File 'lib/bparity/recording.rb', line 299 def install! @boundary.subjects.each_value { |subject| install_subject(subject) } @boundary.externals.each_value { |external| install_external(external) } self end |