Module: Expirable

Defined in:
app/models/expirable.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



27
28
29
# File 'app/models/expirable.rb', line 27

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#expire_from(params) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/models/expirable.rb', line 6

def expire_from(params)
  if params[:expire_now].present? && !expired?
    self.expired_at = Time.now
  elsif params[:expire_in_hour].present? && !expired?
    self.expired_at = 1.hour.from_now
  elsif params[:expire_day_after].present? && !expired?
    self.expired_at = posted_at + 1.day
  elsif params[:expire_3_days_after].present? && !expired?
    self.expired_at = posted_at + 3.days
  elsif params[:expired].present? && params[:expired_at_date].present?
    time = "#{params[:expired_at_date]} #{params[:expired_at_hour]}:#{params[:expired_at_minute]} #{params[:expired_at_meridiem]}"
    time = DateTime.parse time
    time = Time.local time.year, time.month, time.day, time.hour, time.min
    self.expired_at = time
  elsif params[:expired].present?
    self.expired_at = 1.hour.from_now
  else
    self.expired_at = nil
  end
end

#expired?Boolean

Returns:

  • (Boolean)


2
3
4
# File 'app/models/expirable.rb', line 2

def expired?
  expired_at && (expired_at < DateTime.now)
end