Skip to content

Commit

Permalink
Merge pull request #102 from zendesk/ben/expose_formula
Browse files Browse the repository at this point in the history
allow threshold argument to `passes_threshold?` to enable re-use in subclasses
  • Loading branch information
Ben Osheroff committed Dec 6, 2016
2 parents cfd1260 + 1d34cc2 commit c84e81d
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lib/arturo/feature.rb
Expand Up @@ -55,7 +55,7 @@ def enabled_for?(feature_recipient)
return false if feature_recipient.nil?
return false if blacklisted?(feature_recipient)
return true if whitelisted?(feature_recipient)
passes_threshold?(feature_recipient)
passes_threshold?(feature_recipient, deployment_percentage || 0)
end

def name
Expand All @@ -79,10 +79,8 @@ def self.last_updated_at
maximum(:updated_at)
end

protected

def passes_threshold?(feature_recipient)
threshold = self.deployment_percentage || 0
# made public so as to allow for thresholds stored outside of the model
def passes_threshold?(feature_recipient, threshold)
return true if threshold == 100
return false if threshold == 0 || !feature_recipient.id
(((feature_recipient.id + (self.id || 1) + 17) * 13) % 100) < threshold
Expand Down

0 comments on commit c84e81d

Please sign in to comment.