Class: TaskwarriorWeb::Task
- Inherits:
-
Object
- Object
- TaskwarriorWeb::Task
- Defined in:
- lib/taskwarrior-web/model/task.rb
Overview
MAIN TASK CLASS
Instance Attribute Summary collapse
-
#_errors ⇒ Object
Returns the value of attribute _errors.
-
#annotations ⇒ Object
Returns the value of attribute annotations.
-
#depends ⇒ Object
Returns the value of attribute depends.
-
#description ⇒ Object
Returns the value of attribute description.
-
#due ⇒ Object
Returns the value of attribute due.
-
#end ⇒ Object
Returns the value of attribute end.
-
#entry ⇒ Object
Returns the value of attribute entry.
-
#priority ⇒ Object
Returns the value of attribute priority.
-
#project ⇒ Object
Returns the value of attribute project.
-
#remove_tags ⇒ Object
Returns the value of attribute remove_tags.
-
#start ⇒ Object
Returns the value of attribute start.
-
#status ⇒ Object
Returns the value of attribute status.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#urgency ⇒ Object
Returns the value of attribute urgency.
-
#uuid ⇒ Object
Returns the value of attribute uuid.
-
#wait ⇒ Object
Returns the value of attribute wait.
Class Method Summary collapse
-
.count(*args) ⇒ Object
Get the number of tasks for some paramters.
-
.exists?(uuid) ⇒ Boolean
Whether or not a given task exists.
-
.find(uuid) ⇒ Object
Get a single task by UUID or ID.
-
.method_missing(method_sym, *arguments, &block) ⇒ Object
Define method_missing to implement dynamic finder methods.
-
.query(*args) ⇒ Object
Run queries, returns an array of tasks that meet the criteria.
-
.respond_to?(method_sym, include_private = false) ⇒ Boolean
Implement respond_to? so that our dynamic finders are declared.
Instance Method Summary collapse
- #active? ⇒ Boolean
- #complete! ⇒ Object
- #delete! ⇒ Object
-
#initialize(attributes = {}) ⇒ Task
constructor
MODEL METHODS FOR INDIVIDUAL TASKS.
- #is_valid? ⇒ Boolean
- #save! ⇒ Object
- #to_hash ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Task
MODEL METHODS FOR INDIVIDUAL TASKS
16 17 18 19 20 21 22 23 24 |
# File 'lib/taskwarrior-web/model/task.rb', line 16 def initialize(attributes = {}) attributes.each do |attr, value| send("#{attr}=", value) if respond_to?(attr.to_sym) end @_errors = [] @tags = [] if @tags.nil? @annotations = [] if @annotations.nil? end |
Instance Attribute Details
#_errors ⇒ Object
Returns the value of attribute _errors.
8 9 10 |
# File 'lib/taskwarrior-web/model/task.rb', line 8 def _errors @_errors end |
#annotations ⇒ Object
Returns the value of attribute annotations.
8 9 10 |
# File 'lib/taskwarrior-web/model/task.rb', line 8 def annotations @annotations end |
#depends ⇒ Object
Returns the value of attribute depends.
8 9 10 |
# File 'lib/taskwarrior-web/model/task.rb', line 8 def depends @depends end |
#description ⇒ Object
Returns the value of attribute description.
8 9 10 |
# File 'lib/taskwarrior-web/model/task.rb', line 8 def description @description end |
#due ⇒ Object
Returns the value of attribute due.
8 9 10 |
# File 'lib/taskwarrior-web/model/task.rb', line 8 def due @due end |
#end ⇒ Object
Returns the value of attribute end.
8 9 10 |
# File 'lib/taskwarrior-web/model/task.rb', line 8 def end @end end |
#entry ⇒ Object
Returns the value of attribute entry.
8 9 10 |
# File 'lib/taskwarrior-web/model/task.rb', line 8 def entry @entry end |
#priority ⇒ Object
Returns the value of attribute priority.
8 9 10 |
# File 'lib/taskwarrior-web/model/task.rb', line 8 def priority @priority end |
#project ⇒ Object
Returns the value of attribute project.
8 9 10 |
# File 'lib/taskwarrior-web/model/task.rb', line 8 def project @project end |
#remove_tags ⇒ Object
Returns the value of attribute remove_tags.
8 9 10 |
# File 'lib/taskwarrior-web/model/task.rb', line 8 def @remove_tags end |
#start ⇒ Object
Returns the value of attribute start.
8 9 10 |
# File 'lib/taskwarrior-web/model/task.rb', line 8 def start @start end |
#status ⇒ Object
Returns the value of attribute status.
8 9 10 |
# File 'lib/taskwarrior-web/model/task.rb', line 8 def status @status end |
#tags ⇒ Object
Returns the value of attribute tags.
8 9 10 |
# File 'lib/taskwarrior-web/model/task.rb', line 8 def @tags end |
#urgency ⇒ Object
Returns the value of attribute urgency.
8 9 10 |
# File 'lib/taskwarrior-web/model/task.rb', line 8 def urgency @urgency end |
#uuid ⇒ Object
Returns the value of attribute uuid.
8 9 10 |
# File 'lib/taskwarrior-web/model/task.rb', line 8 def uuid @uuid end |
#wait ⇒ Object
Returns the value of attribute wait.
8 9 10 |
# File 'lib/taskwarrior-web/model/task.rb', line 8 def wait @wait end |
Class Method Details
.count(*args) ⇒ Object
Get the number of tasks for some paramters.
116 117 118 |
# File 'lib/taskwarrior-web/model/task.rb', line 116 def self.count(*args) self.query(*args).count end |
.exists?(uuid) ⇒ Boolean
Whether or not a given task exists. Basically sugar for Task.find, but returns a boolean instead of the actual task.
89 90 91 |
# File 'lib/taskwarrior-web/model/task.rb', line 89 def self.exists?(uuid) !!self.find(uuid) end |
.find(uuid) ⇒ Object
Get a single task by UUID or ID. Returns nil if no such task was found.
80 81 82 83 |
# File 'lib/taskwarrior-web/model/task.rb', line 80 def self.find(uuid) tasks = Parser.parse(Command.new(:query, nil, :uuid => uuid).run) tasks.empty? ? nil : Task.new(tasks.first) end |
.method_missing(method_sym, *arguments, &block) ⇒ Object
Define method_missing to implement dynamic finder methods
121 122 123 124 125 126 127 128 |
# File 'lib/taskwarrior-web/model/task.rb', line 121 def self.method_missing(method_sym, *arguments, &block) match = TaskDynamicFinderMatch.new(method_sym) if match.match? self.query(match.attribute.to_s => arguments.first.to_s) else super end end |
.query(*args) ⇒ Object
Run queries, returns an array of tasks that meet the criteria.
Filters can either be a hash of conditions, or an already-constructed taskwarrior filter string.
For example: { :description => ‘test’, ‘project.not’ => ” } ‘description:test project.not:’
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/taskwarrior-web/model/task.rb', line 103 def self.query(*args) tasks = [] if !args.empty? && args.first.is_a?(String) command = Command.new(:query, nil, :description => args.first) else command = Command.new(:query, nil, *args) end Parser.parse(command.run).each { |result| tasks << Task.new(result) } tasks end |
.respond_to?(method_sym, include_private = false) ⇒ Boolean
Implement respond_to? so that our dynamic finders are declared
131 132 133 134 135 136 137 |
# File 'lib/taskwarrior-web/model/task.rb', line 131 def self.respond_to?(method_sym, include_private = false) if TaskDynamicFinderMatch.new(method_sym).match? true else super end end |
Instance Method Details
#active? ⇒ Boolean
61 62 63 |
# File 'lib/taskwarrior-web/model/task.rb', line 61 def active? status.in? ['pending', 'waiting'] end |
#complete! ⇒ Object
30 31 32 |
# File 'lib/taskwarrior-web/model/task.rb', line 30 def complete! Command.new(:complete, self.uuid).run end |
#delete! ⇒ Object
34 35 36 |
# File 'lib/taskwarrior-web/model/task.rb', line 34 def delete! Command.new(:delete, self.uuid).run end |
#is_valid? ⇒ Boolean
56 57 58 59 |
# File 'lib/taskwarrior-web/model/task.rb', line 56 def is_valid? @_errors << 'You must provide a description' if self.description.blank? @_errors.empty? end |
#save! ⇒ Object
26 27 28 |
# File 'lib/taskwarrior-web/model/task.rb', line 26 def save! @uuid ? Command.new(:update, uuid, self.to_hash).run : Command.new(:add, nil, self.to_hash).run end |
#to_hash ⇒ Object
65 66 67 |
# File 'lib/taskwarrior-web/model/task.rb', line 65 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 |
#to_s ⇒ Object
69 70 71 |
# File 'lib/taskwarrior-web/model/task.rb', line 69 def to_s description.truncate(20) end |