lib/taskwarrior-web/model/task.rb in taskwarrior-web-1.1.4 vs lib/taskwarrior-web/model/task.rb in taskwarrior-web-1.1.5

- old
+ new

@@ -50,13 +50,33 @@ end def to_hash Hash[instance_variables.select { |var| !var.to_s.start_with?('@_') }.map { |var| [var[1..-1].to_sym, instance_variable_get(var)] }] end + + def to_s + description.truncate(20) + end ################################## # CLASS METHODS FOR QUERYING TASKS ################################## + + ## + # Get a single task by UUID or ID. Returns nil if no such task was found. + + def self.find(uuid) + tasks = Parser.parse(Command.new(:query, nil, :uuid => uuid).run) + tasks.empty? ? nil : Task.new(tasks.first) + end + + ## + # Whether or not a given task exists. Basically sugar for Task.find, but + # returns a boolean instead of the actual task. + + def self.exists?(uuid) + !!self.find(uuid) + end ## # Run queries, returns an array of tasks that meet the criteria. # # Filters can either be a hash of conditions, or an already-constructed