lib/taskwarrior/task.rb in taskwarrior-0.0.2 vs lib/taskwarrior/task.rb in taskwarrior-0.0.3
- old
+ new
@@ -1,12 +1,16 @@
require 'active_model'
module TaskWarrior
class Task
- attr_accessor :description, :id, :entry, :status, :uuid, :project, :dependencies, :parent, :children, :priority
+ attr_accessor :description, :id, :entry, :status, :uuid,
+ :project, :dependencies, :parent, :children,
+ :priority, :tags, :annotations,
+ :start_at, :wait_at, :end_at, :due_at
include ActiveModel::Validations
+
validates :description, :id, :entry, :status, :uuid, :presence => true
validates :id, :numericality => { :only_integer => true, :greater_than => 0}
validates :uuid, :format => {:with => /[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/,
@@ -19,34 +23,22 @@
:allow_nil => true,
:allow_blank => true,
:message => "%{value} is not a valid priority"
}
+ include TaskWarrior::Validations
validate :entry_cannot_be_in_the_future
+ validates :start_at, :wait_at, :end_at, :due_at, :with => :must_be_date_or_nil
def initialize(description)
@description = description
@dependencies = []
@children = []
@tags = []
+ @annotations = []
end
- def tags
- @tags
- end
-
def to_s
"Task '#{description}'".tap{|result| result << " <#{uuid}>" if uuid}
- end
-
- private
- def entry_cannot_be_in_the_future
- begin
- if !entry.blank? and entry > DateTime.now
- errors.add(:entry, "can't be in the future")
- end
- rescue
- errors.add(:entry, "must be comparable to DateTime")
- end
end
end
end