Orbit/lib/orbit_model/time_frame.rb

33 lines
645 B
Ruby

module OrbitModel
module TimeFrame
def self.included(base)
base.class_eval do
field :postdate , :type => DateTime
field :deadline , :type => DateTime
before_save :check_deadline
send :include, InstanceMethods
end
end
module InstanceMethods
def is_expired?
Date.today > self.deadline ? true : false rescue false
#some dates might sat as nil so rescue false
end
private
def check_deadline
if(!self.deadline.nil? and (self.deadline < self.postdate ))
self.deadline = nil
end
end
end
end
end