Loading lib/labkit/context.rb +11 −1 Original line number Diff line number Diff line Loading @@ -106,6 +106,12 @@ module Labkit end end def get_attribute(attribute) raw = call_or_value(data[log_key(attribute)]) call_or_value(raw) end protected def assign_attributes(attributes) Loading @@ -130,9 +136,13 @@ module Labkit attr_reader :data def call_or_value(value) value.respond_to?(:call) ? value.call : value end def expand_data data.transform_values do |value| value = value.respond_to?(:call) ? value.call : value value = call_or_value(value) value.presence end.compact Loading spec/labkit/context_spec.rb +20 −0 Original line number Diff line number Diff line Loading @@ -279,6 +279,26 @@ describe Labkit::Context do end end describe "#get_attribute" do where(:set_context, :attribute, :expected_value) do [ [{}, :caller_id, nil], [{ caller_id: "caller" }, :caller_id, "caller"], [{ caller_id: -> { "caller" } }, :caller_id, "caller"], [{ caller_id: -> { "caller" } }, "caller_id", "caller"], [{ caller_id: -> { "caller" } }, "meta.caller_id", "caller"], ] end with_them do it "returns the expected value for the attribute" do described_class.with_context(set_context) do |context| expect(context.get_attribute(attribute)).to eq(expected_value) end end end end def contexts described_class.__send__(:contexts) end Loading Loading
lib/labkit/context.rb +11 −1 Original line number Diff line number Diff line Loading @@ -106,6 +106,12 @@ module Labkit end end def get_attribute(attribute) raw = call_or_value(data[log_key(attribute)]) call_or_value(raw) end protected def assign_attributes(attributes) Loading @@ -130,9 +136,13 @@ module Labkit attr_reader :data def call_or_value(value) value.respond_to?(:call) ? value.call : value end def expand_data data.transform_values do |value| value = value.respond_to?(:call) ? value.call : value value = call_or_value(value) value.presence end.compact Loading
spec/labkit/context_spec.rb +20 −0 Original line number Diff line number Diff line Loading @@ -279,6 +279,26 @@ describe Labkit::Context do end end describe "#get_attribute" do where(:set_context, :attribute, :expected_value) do [ [{}, :caller_id, nil], [{ caller_id: "caller" }, :caller_id, "caller"], [{ caller_id: -> { "caller" } }, :caller_id, "caller"], [{ caller_id: -> { "caller" } }, "caller_id", "caller"], [{ caller_id: -> { "caller" } }, "meta.caller_id", "caller"], ] end with_them do it "returns the expected value for the attribute" do described_class.with_context(set_context) do |context| expect(context.get_attribute(attribute)).to eq(expected_value) end end end end def contexts described_class.__send__(:contexts) end Loading