Skip to content

Commit

Permalink
(FACT-3165) Test patching aggregate with :last_evaluated
Browse files Browse the repository at this point in the history
Fill out later.
  • Loading branch information
tvpartytonight committed Sep 12, 2023
1 parent 27e8250 commit 3332818
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/facter/custom_facts/core/aggregate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ class Aggregate
# @api private
attr_reader :fact

# @!attribute [r] last_evaluated
#
# @return [String]
#
# @api public
attr_reader :last_evaluated

# Create a new aggregated resolution mechanism.
#
# @param name [String] The name of the resolution.
Expand Down Expand Up @@ -101,7 +108,22 @@ def options(options)
#
# @api private
def evaluate(&block)
if @last_evaluated
msg = "Already evaluated #{@name}"
msg << " at #{@last_evaluated}" if msg.is_a? String
msg << ', reevaluating anyways'
log.warn msg
end
instance_eval(&block)

# Ruby 1.9+ provides the source location of procs which can provide useful
# debugging information if a resolution is being evaluated twice. Since 1.8
# doesn't support this we opportunistically provide this information.
@last_evaluated = if block.respond_to? :source_location
block.source_location.join(':')
else
true
end
end

# Define a new chunk for the given aggregate
Expand Down

0 comments on commit 3332818

Please sign in to comment.