Class: BeTaskable::Task
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- BeTaskable::Task
- Defined in:
- lib/be_taskable/task.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#_on_completion ⇒ Object
called when the task is marked as complete by the state machine.
-
#_on_expiration ⇒ Object
expires the task and all the assignments.
-
#_runner ⇒ Object
————————————————————————- Pseudo private ————————————————————————-.
-
#all_assignments_done? ⇒ Boolean
————————————————————————- Consensus helpers ————————————————————————-.
- #any_assignment_done? ⇒ Boolean
-
#assignees ⇒ Array
List of current assignees for this task.
- #assignment_for(assignee) ⇒ Object
-
#audit ⇒ Object
calls refresh and then tally needs to run for irrelevant.
-
#complete_by(assignee) ⇒ Object
completes the assignment for the given assignee.
-
#consensus? ⇒ Boolean
consensus?.
- #enacted_assignments ⇒ Object
-
#label! ⇒ String
Gets the label from the resolver for this task.
- #majority_of_assignments_done? ⇒ Boolean
-
#on_assignment_completed(assignment) ⇒ Object
hook: called from an assignment when completed.
-
#on_creation ⇒ Object
————————————————————————- Hooks ————————————————————————-.
-
#refresh ⇒ Object
refresh Check that the current assignments are still relevant Create new assignments as needed or deletes them needs to run for irrelevant.
-
#resolver ⇒ Object
resolver.
-
#tally ⇒ Object
tally Check all the completed assignments and decides wherever to complete the task.
Class Method Details
.current ⇒ Object
17 18 19 |
# File 'lib/be_taskable/task.rb', line 17 def self.current self.uncompleted.unexpired end |
Instance Method Details
#_on_completion ⇒ Object
called when the task is marked as complete by the state machine
157 158 159 160 161 |
# File 'lib/be_taskable/task.rb', line 157 def _on_completion self.update_attribute(:completed_at, DateTime.now) assignments.update_all(completed_at: DateTime.now) resolver.on_completion(self) end |
#_on_expiration ⇒ Object
expires the task and all the assignments
164 165 166 167 168 169 170 |
# File 'lib/be_taskable/task.rb', line 164 def _on_expiration self.update_attribute(:expired_at, DateTime.now) assignments.each do |assignment| assignment.expire end resolver.on_expiration(self) end |
#_runner ⇒ Object
Pseudo private
152 153 154 |
# File 'lib/be_taskable/task.rb', line 152 def _runner @runner ||= BeTaskable::TaskRunner.new(self) end |
#all_assignments_done? ⇒ Boolean
Consensus helpers
135 136 137 |
# File 'lib/be_taskable/task.rb', line 135 def all_assignments_done? assignments.all?{ |a| a.completed? } end |
#any_assignment_done? ⇒ Boolean
139 140 141 |
# File 'lib/be_taskable/task.rb', line 139 def any_assignment_done? assignments.any?{ |a| a.completed? } end |
#assignees ⇒ Array
Returns List of current assignees for this task.
87 88 89 |
# File 'lib/be_taskable/task.rb', line 87 def assignees assignments.map(&:assignee) end |
#assignment_for(assignee) ⇒ Object
96 97 98 |
# File 'lib/be_taskable/task.rb', line 96 def assignment_for(assignee) assignments.where(assignee_id: assignee.id).last end |
#audit ⇒ Object
calls refresh and then tally needs to run for irrelevant
61 62 63 64 65 |
# File 'lib/be_taskable/task.rb', line 61 def audit return if completed? refresh tally end |
#complete_by(assignee) ⇒ Object
completes the assignment for the given assignee
70 71 72 73 74 |
# File 'lib/be_taskable/task.rb', line 70 def complete_by(assignee) assignment = assignment_for(assignee) return false unless assignment assignment.complete end |
#consensus? ⇒ Boolean
consensus?
78 79 80 |
# File 'lib/be_taskable/task.rb', line 78 def consensus? resolver.consensus?(self) end |
#enacted_assignments ⇒ Object
100 101 102 |
# File 'lib/be_taskable/task.rb', line 100 def enacted_assignments assignments.enacted end |
#label! ⇒ String
Returns Gets the label from the resolver for this task.
92 93 94 |
# File 'lib/be_taskable/task.rb', line 92 def label! resolver.label_for_task(self) end |
#majority_of_assignments_done? ⇒ Boolean
143 144 145 146 |
# File 'lib/be_taskable/task.rb', line 143 def majority_of_assignments_done? done = assignments.find_all{ |a| a.completed? } done.size > (assignments.size.to_f / 2) end |
#on_assignment_completed(assignment) ⇒ Object
hook: called from an assignment when completed
127 128 129 |
# File 'lib/be_taskable/task.rb', line 127 def on_assignment_completed(assignment) tally end |
#on_creation ⇒ Object
Hooks
122 123 124 |
# File 'lib/be_taskable/task.rb', line 122 def on_creation resolver.on_creation(self) end |
#refresh ⇒ Object
refresh Check that the current assignments are still relevant Create new assignments as needed or deletes them needs to run for irrelevant
46 47 48 49 |
# File 'lib/be_taskable/task.rb', line 46 def refresh return if completed? _runner.refresh end |
#resolver ⇒ Object
resolver
106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/be_taskable/task.rb', line 106 def resolver if taskable taskable.task_resolver_for_action(action) else # puts self.id # puts self.taskable_id # puts self.taskable_type # puts self.taskable raise "Cannot find taskable" end end |
#tally ⇒ Object
tally Check all the completed assignments and decides wherever to complete the task
54 55 56 57 |
# File 'lib/be_taskable/task.rb', line 54 def tally return if completed? complete if consensus? end |