1
0
Fork 0

Some refactoring

This commit is contained in:
Alex Kotov 2019-01-31 05:33:14 +05:00
parent 34b26bb5da
commit c4be93831c
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08

View file

@ -33,25 +33,14 @@ class Person < ApplicationRecord
private private
def possible_member def possible_member
return if member_since.nil? errors.add :member_since unless member_since_not_before_supporter_since?
return errors.add :member_since if supporter_since.nil?
return errors.add :member_since if member_since < supporter_since
nil
end end
def possible_excluded def possible_excluded
return if excluded_since.nil? return if excluded_since_not_before_member_since? ||
excluded_since_not_before_supporter_since?
return errors.add :excluded_since if supporter_since.nil? && errors.add :excluded_since
member_since.nil?
return errors.add :excluded_since if supporter_since &&
excluded_since < supporter_since
return errors.add :excluded_since if member_since &&
excluded_since < member_since
nil
end end
def supporter_since_not_in_future def supporter_since_not_in_future
@ -66,6 +55,18 @@ private
errors.add :excluded_since unless excluded_since_not_in_future? errors.add :excluded_since unless excluded_since_not_in_future?
end end
def member_since_not_before_supporter_since?
member_since.nil? || supporter_since && member_since >= supporter_since
end
def excluded_since_not_before_supporter_since?
excluded_since.nil? || supporter_since && excluded_since >= supporter_since
end
def excluded_since_not_before_member_since?
excluded_since.nil? || member_since && excluded_since >= member_since
end
def supporter_since_not_in_future? def supporter_since_not_in_future?
supporter_since.nil? || supporter_since <= Time.zone.today supporter_since.nil? || supporter_since <= Time.zone.today
end end