-
-
Save katpadi/7d6829c373a3aa91002a to your computer and use it in GitHub Desktop.
TransactionLimitChecker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TransactionLimitChecker | |
def initialize(transaction) | |
@transaction = transaction | |
end | |
def limit_is_reached?(user) | |
per_user_limit_reached?(user) || | |
per_interval_limit_reached?(user) || | |
overall_max_limit_reached? | |
end | |
def per_user_limit_reached?(user) | |
# Lots of logic here | |
# of | |
# logic | |
# here... | |
@transaction.count > some_count | |
end | |
def per_interval_limit_reached?(user) | |
# Logic... | |
# put here your logic | |
# Use some private methods...whatever | |
check_interval_validity! | |
limit = blah | |
Time.current.utc <= @transaction.updated_at.time + limit | |
end | |
def overall_max_limit_reached? | |
# More logic! | |
# Just put 'em here | |
@transaction.over_all_submission_count > total_something | |
end | |
private | |
def check_interval_validity! | |
# Check interval unit if valid ActiveSupport::Duration | |
valid = 1.respond_to? @transaction.submission_interval_unit.to_sym | |
fail Errors::InvalidIntervalDefined unless valid | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment