module Flog::PayloadValueShuntable

PayloadValueShuntable enables to shunt value in payload

Public Instance Methods

shunt_if_key_already_exists(payload, key, temp_value, block) click to toggle source
# File lib/flog/payload_value_shuntable.rb, line 16
def shunt_if_key_already_exists(payload, key, temp_value, block)
  base_value = payload[key]
  begin
    payload[key] = temp_value
    block.call
  ensure
    payload[key] = base_value
  end
end
shunt_if_key_not_exist(payload, key, temp_value, block) click to toggle source
# File lib/flog/payload_value_shuntable.rb, line 26
def shunt_if_key_not_exist(payload, key, temp_value, block)
  payload[key] = temp_value
  block.call
ensure
  payload.delete(key)
end
shunt_payload_value(payload, key, temp_value, &block) click to toggle source
# File lib/flog/payload_value_shuntable.rb, line 6
def shunt_payload_value(payload, key, temp_value, &block)
  return unless block

  if payload.key?(key)
    shunt_if_key_already_exists(payload, key, temp_value, block)
  else
    shunt_if_key_not_exist(payload, key, temp_value, block)
  end
end