blob: 62f8d5028fd8c3b90a4bde8f6dd38cfe85de39c2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
class Commit
include ActiveModel::Model
include ActiveModel::Validations
ATTRIBUTES = %i[id
author
email
date
message
files
packages
created_at
updated_at].freeze
attr_accessor(*ATTRIBUTES)
attr_reader :attributes
def initialize(attr = {})
attr.each do |k, v|
send("#{k}=", v) if ATTRIBUTES.include?(k.to_sym)
end
end
def attributes
@created_at ||= DateTime.now
@updated_at = DateTime.now
ATTRIBUTES.each_with_object({}) do |attr, hash|
if (value = send(attr))
hash[attr] = value
end
end
end
alias to_hash attributes
end
|