Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
gardleopard committed Jul 4, 2023
1 parent f2856ac commit 000d92c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/unleash/strategy/flexible_rollout.rb
Expand Up @@ -12,7 +12,7 @@ def is_enabled?(params = {}, context = nil)
return false unless params.is_a?(Hash)

stickiness = params.fetch('stickiness', 'default')
return false unless context.instance_of?(Unleash::Context) || ['random', 'default'].include?(stickiness)
return false unless context_is_sufficient?(stickiness, context)

stickiness_id = resolve_stickiness(stickiness, context)

Expand All @@ -33,6 +33,12 @@ def is_enabled?(params = {}, context = nil)

private

def context_is_sufficient?(stickiness, context)
return true if ['random', 'default'].include?(stickiness)

context.instance_of?(Unleash::Context)
end

def random
Random.rand(0..100)
end
Expand Down

0 comments on commit 000d92c

Please sign in to comment.