Let say I have a model named a
Product has a
days_lifetime:integer in days (it can expire in 1, 2, 3 et.c. days after initialization). But sometimes
Product has unlimited lifetime (it can be stored infinitively long time). So, I need to add another variable like
Now I have two ways to understand the lifetime of
class Product < AR::Base def lifetime unlimited_lifetime? ? 100000 : days_lifetime # too big integer end validates :unlimited_lifetime, absence: true, if: 'days_lifetime.present?' validates :unlimited_lifetime, presence: true, if: 'days_lifetime.blank?' validates :days_lifetime, absence: true, if: 'unlimited_lifetime.present?' validatees :days_lifetime, presence: true, if: 'unlimited_lifetime.blank?'
But this solution is complex and hardcoded. Is there any software pattern or gem to simplify this approach?