2015-10-06 15:21:46 +03:00
|
|
|
class TalkPreference < ActiveRecord::Base
|
|
|
|
self.primary_key = :unique_id
|
|
|
|
|
|
|
|
serialize :talks, Array
|
|
|
|
|
|
|
|
before_create :assign_new_unique_id
|
|
|
|
|
2015-10-13 14:34:45 +03:00
|
|
|
def include?(id)
|
|
|
|
talks.include? id.to_s
|
|
|
|
end
|
|
|
|
|
2015-10-15 02:01:03 +03:00
|
|
|
def include_all?(ids)
|
|
|
|
ids.all? { |id| include? id }
|
|
|
|
end
|
|
|
|
|
2016-10-04 14:00:30 +03:00
|
|
|
def self.this_years
|
|
|
|
timespan = Time.now.change(month: 1, day: 1, hour: 0)..Time.now.change(month: 12, day: 1, hour: 0)
|
|
|
|
where created_at: timespan
|
|
|
|
end
|
|
|
|
|
2015-10-06 15:21:46 +03:00
|
|
|
private
|
|
|
|
|
|
|
|
def assign_new_unique_id
|
|
|
|
self.unique_id = SecureRandom.uuid
|
|
|
|
self.hashed_unique_id = Digest::SHA1.hexdigest(self.unique_id)
|
|
|
|
end
|
|
|
|
end
|