diff options
Diffstat (limited to 'app/models/commit.rb')
-rw-r--r-- | app/models/commit.rb | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb new file mode 100644 index 0000000..2512ced --- /dev/null +++ b/app/models/commit.rb @@ -0,0 +1,37 @@ +class Commit + include ActiveModel::Model + include ActiveModel::Validations + + ATTRIBUTES = [:id, + :author, + :email, + :date, + :message, + :files, + :packages, + :created_at, + :updated_at] + attr_accessor(*ATTRIBUTES) + attr_reader :attributes + + def initialize(attr={}) + attr.each do |k,v| + if ATTRIBUTES.include?(k.to_sym) + send("#{k}=", v) + end + end + end + + def attributes + @created_at ||= DateTime.now + @updated_at = DateTime.now + ATTRIBUTES.inject({}) do |hash, attr| + if value = send(attr) + hash[attr] = value + end + hash + end + end + alias :to_hash :attributes + +end |