Class: Trailblazer::Developer::Trace::Snapshot::Versions
- Inherits:
-
Object
- Object
- Trailblazer::Developer::Trace::Snapshot::Versions
- Defined in:
- lib/trailblazer/developer/trace/snapshot/versions.rb
Overview
A table of all ctx variables, their hashes and serialized values.
{:current_user=>
{3298051090906520533=>"#<TraceTest::User:0x000055b2e3424460 @id=1>",
3764938782671692590=>"#<TraceTest::User:0x000055b2e33e45b8 @id=2>"},
:params=>
{2911818769466875657=>"{:name=>\"Q & I\"}",
2238394858183550663=>"{:name=>\"Q & I\", :song=>{...}}"},
:seq=>
{-105020188158523405=>"[]",
-2281497291400788995=>"[:authenticate]",
150926802063554866=>"[:authenticate, :authorize]",
3339595138798116233=>"[:authenticate, :authorize, :model]",
-3395325862879242711=>
"[:authenticate, :authorize, :model, :screw_params!]"},
:model=>{348183403054247453=>"Object"}}
Instance Method Summary collapse
- #add_changes!(new_versions) ⇒ Object
- #add_variable_version!(name, hash, value) ⇒ Object
-
#changeset_for(ctx, value_snapshooter:) ⇒ Object
DISCUSS: problem with changeset is, we have to go through variables twice.
-
#initialize ⇒ Versions
constructor
A new instance of Versions.
- #to_h ⇒ Object
Constructor Details
#initialize ⇒ Versions
Returns a new instance of Versions.
59 60 61 |
# File 'lib/trailblazer/developer/trace/snapshot/versions.rb', line 59 def initialize @variables = {} end |
Instance Method Details
#add_changes!(new_versions) ⇒ Object
86 87 88 89 90 |
# File 'lib/trailblazer/developer/trace/snapshot/versions.rb', line 86 def add_changes!(new_versions) new_versions.each do |args| add_variable_version!(*args) end end |
#add_variable_version!(name, hash, value) ⇒ Object
93 94 95 96 97 |
# File 'lib/trailblazer/developer/trace/snapshot/versions.rb', line 93 def add_variable_version!(name, hash, value) @variables[name] ||= {} @variables[name][hash] = value # i hate mutations. end |
#changeset_for(ctx, value_snapshooter:) ⇒ Object
DISCUSS: problem with changeset is, we have to go through variables twice.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/trailblazer/developer/trace/snapshot/versions.rb', line 64 def changeset_for(ctx, value_snapshooter:) new_versions = [] changeset_for_snapshot = ctx.collect do |name, value| # DISCUSS: do we have to call that explicitly or does Hash#[] do that for us, anyway? value_hash = value.hash # DISCUSS: does this really always change when a deeply nested object changes? if (variable_versions = @variables[name]) && variable_versions.key?(value_hash) # TODO: test {variable: nil} value [name, value_hash, nil] # nil means it's an existing reference. else value_snapshot = value_snapshooter.(name, value, ctx: ctx) version = [name, value_hash, value_snapshot] new_versions << version version end end return changeset_for_snapshot, new_versions end |
#to_h ⇒ Object
99 100 101 |
# File 'lib/trailblazer/developer/trace/snapshot/versions.rb', line 99 def to_h @variables end |