lib/labkit/context.rb in gitlab-labkit-0.15.0 vs lib/labkit/context.rb in gitlab-labkit-0.16.0
- old
+ new
@@ -104,10 +104,16 @@
to_h.except(CORRELATION_ID_KEY).transform_keys do |key|
self.class.header_name(key)
end
end
+ def get_attribute(attribute)
+ raw = call_or_value(data[log_key(attribute)])
+
+ call_or_value(raw)
+ end
+
protected
def assign_attributes(attributes)
attributes = attributes.transform_keys(&method(:log_key))
attributes = attributes.slice(*known_log_keys)
@@ -128,12 +134,16 @@
delegate :log_key, :known_log_keys, to: :class
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
end