Skip to content

Commit

Permalink
Renames
Browse files Browse the repository at this point in the history
  • Loading branch information
keelerm84 committed Mar 21, 2024
1 parent 8028633 commit aea01b5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 deletions.
19 changes: 10 additions & 9 deletions lib/ldclient-rb/interfaces.rb
Original file line number Diff line number Diff line change
Expand Up @@ -902,35 +902,36 @@ module Hook
# @return [Metadata]
#
def metadata
Metadata('UNDEFINED')
Metadata.new('UNDEFINED')
end

#
# The before method is called during the execution of a variation method before the flag value has been
# determined. The method is executed synchronously.
#
# @param hook_context [EvaluationContext] Contains information about the evaluation being performed. This is not
# mutable.
# @param evaluation_series_context [EvaluationSeriesContext] Contains information about the evaluation being
# performed. This is not mutable.
# @param data [Hash] A record associated with each stage of hook invocations. Each stage is called with the data
# of the previous stage for a series. The input record should not be modified.
# @return [Hash] Data to use when executing the next state of the hook in the evaluation series.
#
def before_evaluation(hook_context, data)
def before_evaluation(evaluation_series_context, data)
{}
end

#
# The after method is called during the execution of the variation method
# after the flag value has been determined. The method is executed synchronously.
# The after method is called during the execution of the variation method # after the flag value has been
# determined. The method is executed synchronously.
#
# @param hook_context [EvaluationContext] Contains read-only information about the evaluation being performed.
# @param evaluation_series_context [EvaluationSeriesContext] Contains read-only information about the evaluation
# being performed.
# @param data [Hash] A record associated with each stage of hook invocations. Each stage is called with the data
# of the previous stage for a series.
# @param detail [LaunchDarkly::EvaluationDetail] The result of the evaluation. This value should not be
# modified.
# @return [Hash] Data to use when executing the next state of the hook in the evaluation series.
#
def after_evaluation(hook_context, data, detail)
def after_evaluation(evaluation_series_context, data, detail)
data
end
end
Expand All @@ -949,7 +950,7 @@ def initialize(name)
#
# Contextual information that will be provided to handlers during evaluation series.
#
class EvaluationContext
class EvaluationSeriesContext
attr_reader :key
attr_reader :context
attr_reader :value
Expand Down
26 changes: 13 additions & 13 deletions lib/ldclient-rb/ldclient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,10 @@ def variation_detail(key, context, default)
private def evaluate_with_hooks(key, context, default, method)
return yield if @hooks.empty?

hooks, hook_context = prepare_hooks(key, context, default, method)
hook_data = execute_before_evaluation(hooks, hook_context)
hooks, evaluation_series_context = prepare_hooks(key, context, default, method)
hook_data = execute_before_evaluation(hooks, evaluation_series_context)
evaluation_detail, flag, error = yield
execute_after_evaluation(hooks, hook_context, hook_data, evaluation_detail)
execute_after_evaluation(hooks, evaluation_series_context, hook_data, evaluation_detail)

[evaluation_detail, flag, error]
end
Expand All @@ -287,14 +287,14 @@ def variation_detail(key, context, default)
# raised an uncaught exception, the value will be nil.
#
# @param hooks [Array<Interfaces::Hooks::Hook>]
# @param hook_context [EvaluationContext]
# @param evaluation_series_context [EvaluationSeriesContext]
#
# @return [Array<any>]
#
private def execute_before_evaluation(hooks, hook_context)
private def execute_before_evaluation(hooks, evaluation_series_context)
hooks.map do |hook|
try_execute_stage(:before_evaluation, hook.metadata.name) do
hook.before_evaluation(hook_context, {})
hook.before_evaluation(evaluation_series_context, {})
end
end
end
Expand All @@ -306,16 +306,16 @@ def variation_detail(key, context, default)
# raised an uncaught exception, the value will be nil.
#
# @param hooks [Array<Interfaces::Hooks::Hook>]
# @param hook_context [EvaluationContext]
# @param evaluation_series_context [EvaluationSeriesContext]
# @param hook_data [Array<any>]
# @param evaluation_detail [EvaluationDetail]
#
# @return [Array<any>]
#
private def execute_after_evaluation(hooks, hook_context, hook_data, evaluation_detail)
private def execute_after_evaluation(hooks, evaluation_series_context, hook_data, evaluation_detail)
hooks.zip(hook_data).reverse.map do |(hook, data)|
try_execute_stage(:after_evaluation, hook.metadata.name) do
hook.after_evaluation(hook_context, data, evaluation_detail)
hook.after_evaluation(evaluation_series_context, data, evaluation_detail)
end
end
end
Expand All @@ -336,23 +336,23 @@ def variation_detail(key, context, default)
end

#
# Return a copy of the existing hooks and a few instance of the EvaluationContext used for the evaluation series.
# Return a copy of the existing hooks and a few instance of the EvaluationSeriesContext used for the evaluation series.
#
# @param key [String]
# @param context [LDContext]
# @param default [any]
# @param method [Symbol]
# @return [Array[Array<Interfaces::Hooks::Hook>, Interfaces::Hooks::EvaluationContext]]
# @return [Array[Array<Interfaces::Hooks::Hook>, Interfaces::Hooks::EvaluationSeriesContext]]
#
private def prepare_hooks(key, context, default, method)
# Copy the hooks to use a consistent set during the evaluation series.
#
# Hooks can be added and we want to ensure all correct stages for a given hook execute. For example, we do not
# want to trigger the after_evaluation method without also triggering the before_evaluation method.
hooks = @hooks.dup
hook_context = Interfaces::Hooks::EvaluationContext.new(key, context, default, method)
evaluation_series_context = Interfaces::Hooks::EvaluationSeriesContext.new(key, context, default, method)

[hooks, hook_context]
[hooks, evaluation_series_context]
end

#
Expand Down
8 changes: 4 additions & 4 deletions spec/mock_components.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ def metadata
Interfaces::Hooks::Metadata.new("mock hook")
end

def before_evaluation(hook_context, data)
@before_evaluation.call(hook_context, data)
def before_evaluation(evaluation_series_context, data)
@before_evaluation.call(evaluation_series_context, data)
end

def after_evaluation(hook_context, data, detail)
@after_evaluation.call(hook_context, data, detail)
def after_evaluation(evaluation_series_context, data, detail)
@after_evaluation.call(evaluation_series_context, data, detail)
end
end
end

0 comments on commit aea01b5

Please sign in to comment.