Skip to content

Commit

Permalink
refactor: make method name more clear and return object better
Browse files Browse the repository at this point in the history
  • Loading branch information
gardleopard committed Aug 22, 2023
1 parent ccbd524 commit 30a3dbb
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/unleash/feature_toggle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def get_variant(context, fallback_variant = Unleash::FeatureToggle.disabled_vari

toggle_enabled = am_enabled?(context)

strategy = am_enabled(context)[:strategy]
strategy = evaluate(context)[:strategy]

group_id = strategy&.params&.fetch('groupId', self.name) || self.name
variants = strategy&.variants || self.variant_definitions
Expand Down Expand Up @@ -70,23 +70,23 @@ def resolve_stickiness(variants)

# only check if it is enabled, do not do metrics
def am_enabled?(context)
am_enabled(context)[:result]
evaluate(context)[:is_enabled]
end

def am_enabled(context)
def evaluate(context)
returnable = {
result: false,
is_enabled: false,
strategy: nil
}
return returnable unless self.enabled

if self.strategies.empty?
returnable[:result] = true
returnable[:is_enabled] = true
else
returnable[:strategy] = self.strategies.find(proc{ nil }) do |s|
(strategy_enabled?(s, context) && strategy_constraint_matches?(s, context))
end
returnable[:result] = true if returnable[:strategy]
returnable[:is_enabled] = true if returnable[:strategy]
end

Unleash.logger.debug "Unleash::FeatureToggle (enabled:#{self.enabled} " \
Expand Down

0 comments on commit 30a3dbb

Please sign in to comment.