lib/sawmill/record.rb in sawmill-0.0.2 vs lib/sawmill/record.rb in sawmill-0.0.3
- old
+ new
@@ -70,10 +70,11 @@
@started = false
@complete = false
@message_count = 0
@entries = []
@attributes = {}
+ @computations = {}
if entries_ && entries_.size > 0
entries_.each do |entry_|
add_entry(entry_)
end
end
@@ -254,9 +255,22 @@
# Get an array of attribute keys present in this log record.
def attribute_keys
@attributes.keys
+ end
+
+
+ # Compute and cache a value.
+ # This is a convenient way for RecordProcessor objects to share
+ # computed information about a record.
+ #
+ # Returns the computed value with the given key.
+ # If the given key has not been computed yet, computes it by
+ # calling the given block and passing self.
+
+ def compute(key_)
+ @computations[key_] ||= yield self
end
end