aboutsummaryrefslogtreecommitdiff
blob: 798923664add8c80982bf74ed3e79dea0494da06 (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
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)

  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