Class: Trailblazer::Developer::Trace::Snapshot::Value

Inherits:
Object
  • Object
show all
Defined in:
lib/trailblazer/developer/trace/snapshot/value.rb

Overview

Value serializes the variable value using with custom logic, e.g. valuevalue.inspect. A series of matchers decide which snapshooter is used.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(matchers) ⇒ Value

Returns a new instance of Value.



7
8
9
# File 'lib/trailblazer/developer/trace/snapshot/value.rb', line 7

def initialize(matchers)
  @matchers = matchers
end

Class Method Details

.buildObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/trailblazer/developer/trace/snapshot/value.rb', line 26

def self.build
  new(
    [
      [
        ->(*) { true }, # matches everything
        method(:default_variable_inspect)
      ]
    ]
  )
end

.default_variable_inspect(name, value, ctx:) ⇒ Object



22
23
24
# File 'lib/trailblazer/developer/trace/snapshot/value.rb', line 22

def self.default_variable_inspect(name, value, ctx:)
  value.inspect
end

Instance Method Details

#call(name, value, **options) ⇒ Object

DISCUSS: this could be a compiled pattern matching ‘case/in` block here.



12
13
14
15
16
17
18
19
20
# File 'lib/trailblazer/developer/trace/snapshot/value.rb', line 12

def call(name, value, **options)
  @matchers.each do |matcher, inspect_method|
    if matcher.(name, value, **options)
      return inspect_method.(name, value, **options)
    end
  end

  raise "no matcher found for #{name.inspect}" # TODO: this should never happen.
end