lib/taskwarrior-web/task.rb in taskwarrior-web-0.0.10 vs lib/taskwarrior-web/task.rb in taskwarrior-web-0.0.11

- old
+ new

@@ -1,16 +1,17 @@ +require 'taskwarrior-web/runner' + module TaskwarriorWeb ################# # MAIN TASK CLASS ################# class Task - TASK_BIN = 'task' - attr_accessor :id, :entry, :project, :priority, :uuid, :description, :status, - :due, :start, :end, :tags, :depends, :wait + :due, :start, :end, :tags, :depends, :wait, :annotations + alias :annotate= :annotations= #################################### # MODEL METHODS FOR INDIVIDUAL TASKS #################################### @@ -20,23 +21,22 @@ end end def save! exclude = ['@description', '@tags'] - command = TASK_BIN + ' add' + command = 'add' command << " '#{description}'" instance_variables.each do |ivar| subbed = ivar.to_s.gsub('@', '') command << " #{subbed}:#{send(subbed.to_sym)}" unless exclude.include?(ivar.to_s) end unless tags.nil? tags.gsub(', ', ',').split(',').each do |tag| command << " +#{tag}" end end - puts command - `#{command}` + TaskwarriorWeb::Runner.run(command) end ################################## # CLASS METHODS FOR QUERYING TASKS ################################## @@ -44,19 +44,19 @@ # Run queries on tasks. def self.query(*args) tasks = [] count = 1 - stdout = TASK_BIN + ' _query' + command = '_query' args.each do |param| param.each do |attr, value| - stdout << " #{attr.to_s}:#{value}" + command << " #{attr.to_s}:#{value}" end end # Process the JSON data. - json = `#{stdout}` + json = TaskwarriorWeb::Runner.run(command) json.strip! json = '[' + json + ']' results = json == '[No matches.]' ? [] : JSON.parse(json) results.each do |result| @@ -86,28 +86,27 @@ end end # Get the number of tasks for some paramters def self.count(*args) - statement = TASK_BIN + ' count' + command = 'count' args.each do |param| param.each do |attr, value| - statement << " #{attr.to_s}:#{value}" + command << " #{attr.to_s}:#{value}" end end - return `#{statement}`.strip! + return TaskwarriorWeb::Runner.run(command).strip! end ############################################### # CLASS METHODS FOR INTERACTING WITH TASKS # (THESE WILL PROBABLY BECOME INSTANCE METHODS) ############################################### # Mark a task as complete # TODO: Make into instance method when `task` supports finding by UUID. def self.complete!(task_id) - statement = TASK_BIN + " #{task_id} done" - `#{statement}` + TaskwarriorWeb::Runner.run("#{task_id} done") end end ###########################################