lib/taskwarrior/task.rb in taskwarrior-0.0.4 vs lib/taskwarrior/task.rb in taskwarrior-0.0.5

- old
+ new

@@ -1,30 +1,36 @@ -require 'active_model' - module TaskWarrior class Task - attr_accessor :description, :id, :entry, :status, :uuid, - :project, :dependencies, :parent, :children, - :priority, :tags, :annotations, - :start_at, :wait_at, :end_at, :due_at + include TaskWarrior::Attributes + attributes :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 :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}/, - :message => "'%{value}' does not match the expected format of a UUID"} + validates :uuid, :format => { + :with => /[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/, + :message => "'%{value}' does not match the expected format of a UUID" + } - validates :status, :inclusion => {:in => [:pending, :waiting, :complete], :message => "%{value} is not a valid status"} + validates :status, :inclusion => { + :in => [:pending, :waiting, :complete], + :message => "%{value} is not a valid status" + } validates :priority, :inclusion => { - :in => [:high, :medium, :low], - :allow_nil => true, + :in => [:high, :medium, :low], + :allow_nil => true, :allow_blank => true, - :message => "%{value} is not a valid priority" + :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 @@ -44,16 +50,10 @@ "Task '#{description}'".tap{|result| result << " <#{uuid}>" if uuid} end # other may have the same uuid, but if its attributes differ, it will not be equal def eql?(other) - # TODO Find a way to call attributes instead of listing them here again - # Maybe Virtus? - # http://solnic.eu/2012/01/10/ruby-datamapper-status.html - [:description, :id, :entry, :status, :uuid, - :project, :dependencies, :parent, :children, - :priority, :tags, :annotations, :start_at, :wait_at, - :end_at, :due_at].each do |attr| + self.class.attributes.each do |attr| return false unless send(attr).eql?(other.send(attr)) end end def hash