Class: Bumbleworks::Task
- Inherits:
-
Object
- Object
- Bumbleworks::Task
- Extended by:
- Forwardable
- Defined in:
- lib/bumbleworks/task.rb
Defined Under Namespace
Classes: AlreadyClaimed, EntityNotFound, MissingWorkitem
Instance Attribute Summary collapse
-
#nickname ⇒ Object
readonly
Returns the value of attribute nickname.
Class Method Summary collapse
- .all ⇒ Object
-
.autoload_all(options = {}) ⇒ Object
Autoload all task modules defined in files in the tasks_directory.
- .find_by_id(sid) ⇒ Object
- .for_role(identifier) ⇒ Object
- .for_roles(identifiers) ⇒ Object
- .from_workitems(workitems) ⇒ Object
- .storage_participant ⇒ Object
Instance Method Summary collapse
-
#[](key) ⇒ Object
alias for fields[] (fields delegated to workitem).
-
#[]=(key, value) ⇒ Object
alias for fields[]= (fields delegated to workitem).
-
#claim(token) ⇒ Object
Claim task and assign token to claimant.
-
#claimant ⇒ Object
Token used to claim task, nil if not claimed.
-
#claimed? ⇒ Boolean
true if task is claimed.
-
#complete(params = {}) ⇒ Object
proceed workitem (saving changes to fields).
- #entity ⇒ Object
- #extend_module ⇒ Object
- #has_entity_fields? ⇒ Boolean
-
#initialize(workitem) ⇒ Task
constructor
A new instance of Task.
-
#release ⇒ Object
release claim on task.
- #role ⇒ Object
- #task_module ⇒ Object
-
#update(params = {}) ⇒ Object
update workitem with changes to fields & params.
Constructor Details
#initialize(workitem) ⇒ Task
Returns a new instance of Task.
64 65 66 67 68 69 70 71 |
# File 'lib/bumbleworks/task.rb', line 64 def initialize(workitem) @workitem = workitem unless workitem && workitem.is_a?(::Ruote::Workitem) raise ArgumentError, "Not a valid workitem" end @nickname = params['task'] extend_module end |
Instance Attribute Details
#nickname ⇒ Object (readonly)
Returns the value of attribute nickname.
11 12 13 |
# File 'lib/bumbleworks/task.rb', line 11 def nickname @nickname end |
Class Method Details
.all ⇒ Object
41 42 43 |
# File 'lib/bumbleworks/task.rb', line 41 def all from_workitems(storage_participant.all) end |
.autoload_all(options = {}) ⇒ Object
Autoload all task modules defined in files in the tasks_directory. The symbol for autoload comes from the camelized version of the filename, so this method is dependent on following that convention. For example, file ‘chew_cud_task.rb` should define `ChewCudTask`.
22 23 24 25 26 27 |
# File 'lib/bumbleworks/task.rb', line 22 def autoload_all( = {}) [:directory] ||= Bumbleworks.tasks_directory Bumbleworks::Support.all_files([:directory], :camelize => true).each do |path, name| Object.autoload name.to_sym, path end end |
.find_by_id(sid) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/bumbleworks/task.rb', line 45 def find_by_id(sid) workitem = storage_participant[sid] if sid raise MissingWorkitem unless workitem new(workitem) rescue ArgumentError => e raise MissingWorkitem, e. end |
.for_role(identifier) ⇒ Object
29 30 31 |
# File 'lib/bumbleworks/task.rb', line 29 def for_role(identifier) for_roles([identifier]) end |
.for_roles(identifiers) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/bumbleworks/task.rb', line 33 def for_roles(identifiers) return [] unless identifiers.is_a?(Array) workitems = identifiers.collect { |identifier| storage_participant.by_participant(identifier) }.flatten.uniq from_workitems(workitems) end |
.from_workitems(workitems) ⇒ Object
57 58 59 60 61 |
# File 'lib/bumbleworks/task.rb', line 57 def from_workitems(workitems) workitems.map { |wi| new(wi) if wi.params['task'] }.compact end |
.storage_participant ⇒ Object
53 54 55 |
# File 'lib/bumbleworks/task.rb', line 53 def storage_participant Bumbleworks.dashboard.storage_participant end |
Instance Method Details
#[](key) ⇒ Object
alias for fields[] (fields delegated to workitem)
87 88 89 |
# File 'lib/bumbleworks/task.rb', line 87 def [](key) fields[key] end |
#[]=(key, value) ⇒ Object
alias for fields[]= (fields delegated to workitem)
92 93 94 |
# File 'lib/bumbleworks/task.rb', line 92 def []=(key, value) fields[key] = value end |
#claim(token) ⇒ Object
Claim task and assign token to claimant
134 135 136 |
# File 'lib/bumbleworks/task.rb', line 134 def claim(token) set_claimant(token) end |
#claimant ⇒ Object
Token used to claim task, nil if not claimed
129 130 131 |
# File 'lib/bumbleworks/task.rb', line 129 def claimant params['claimant'] end |
#claimed? ⇒ Boolean
true if task is claimed
139 140 141 |
# File 'lib/bumbleworks/task.rb', line 139 def claimed? !claimant.nil? end |
#complete(params = {}) ⇒ Object
proceed workitem (saving changes to fields)
120 121 122 123 124 125 126 |
# File 'lib/bumbleworks/task.rb', line 120 def complete(params = {}) before_update(params) before_complete(params) proceed_workitem after_complete(params) after_update(params) end |
#entity ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/bumbleworks/task.rb', line 73 def entity if has_entity_fields? klass = Bumbleworks::Support.constantize(fields['entity_type']) entity = klass.first_by_identifier(fields['entity_id']) end raise EntityNotFound unless entity entity end |
#extend_module ⇒ Object
100 101 102 103 104 |
# File 'lib/bumbleworks/task.rb', line 100 def extend_module extend Bumbleworks::Tasks::Base extend task_module if nickname rescue NameError end |
#has_entity_fields? ⇒ Boolean
82 83 84 |
# File 'lib/bumbleworks/task.rb', line 82 def has_entity_fields? fields['entity_id'] && fields['entity_type'] end |
#release ⇒ Object
release claim on task.
144 145 146 |
# File 'lib/bumbleworks/task.rb', line 144 def release set_claimant(nil) end |
#role ⇒ Object
96 97 98 |
# File 'lib/bumbleworks/task.rb', line 96 def role participant_name end |
#task_module ⇒ Object
106 107 108 109 110 |
# File 'lib/bumbleworks/task.rb', line 106 def task_module return nil unless nickname klass_name = Bumbleworks::Support.camelize(nickname) klass = Bumbleworks::Support.constantize("#{klass_name}Task") end |
#update(params = {}) ⇒ Object
update workitem with changes to fields & params
113 114 115 116 117 |
# File 'lib/bumbleworks/task.rb', line 113 def update(params = {}) before_update(params) update_workitem after_update(params) end |