1class EmailRequestedReceipt < ActiveRecord::Base |
|
2 belongs_to :petition, touch: true |
|
4 validates :petition, presence: true |
|
5 validates :petition_id, uniqueness: true |
|
|
7 def get(name) |
8 raise ArgumentError unless valid_timestamp?(name) |
|
9 self[name] |
|
10 end |
|
|
12 def set(name, time) |
13 raise ArgumentError unless valid_timestamp?(name) |
|
14 update_column(name, time)
|
|
15 end |
|
17 private
|
|
|
18 def valid_timestamp?(name) |
19 possible_timestamps.include? name
|
|
20 end |
|
|
22 def possible_timestamps |
23 @_possiblities ||= attributes.keys - ['id', 'petition_id', 'created_at', 'updated_at'] |
|
24 end |
|
25end |