class Bumbleworks::Task
Attributes
nickname[R]
workitem[R]
Public Class Methods
autoload_all(options = {})
click to toggle source
@public 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`.
# File lib/bumbleworks/task.rb, line 33 def autoload_all(options = {}) if directory = options[:directory] || Bumbleworks.tasks_directory Bumbleworks::Support.all_files(directory, :camelize => true).each do |path, name| Object.autoload name.to_sym, path end end end
find_by_id(sid)
click to toggle source
# File lib/bumbleworks/task.rb, line 48 def find_by_id(sid) workitem = storage_participant[sid] if sid raise MissingWorkitem unless workitem new(workitem) rescue ArgumentError => e raise MissingWorkitem, e.message end
method_missing(method, *args, &block)
click to toggle source
Calls superclass method
# File lib/bumbleworks/task.rb, line 41 def method_missing(method, *args, &block) if Finder.new.respond_to?(method) return Finder.new(self).send(method, *args, &block) end super end
new(workitem)
click to toggle source
# File lib/bumbleworks/task.rb, line 61 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
storage_participant()
click to toggle source
# File lib/bumbleworks/task.rb, line 56 def storage_participant Bumbleworks.dashboard.storage_participant end
Public Instance Methods
[](key)
click to toggle source
alias for fields[] (fields delegated to workitem)
# File lib/bumbleworks/task.rb, line 76 def [](key) fields[key] end
[]=(key, value)
click to toggle source
alias for fields[]= (fields delegated to workitem)
# File lib/bumbleworks/task.rb, line 81 def []=(key, value) fields[key] = value end
call_after_hooks(action, *args)
click to toggle source
# File lib/bumbleworks/task.rb, line 107 def call_after_hooks(action, *args) call_hooks(:after, action, *args) end
call_before_hooks(action, *args)
click to toggle source
# File lib/bumbleworks/task.rb, line 103 def call_before_hooks(action, *args) call_hooks(:before, action, *args) end
claim(token, options = {})
click to toggle source
Claim task and assign token to claimant
# File lib/bumbleworks/task.rb, line 149 def claim(token, options = {}) with_hooks(:claim, token, options) do set_claimant(token) log(:claim) end end
claimant()
click to toggle source
Token used to claim task, nil if not claimed
# File lib/bumbleworks/task.rb, line 139 def claimant params['claimant'] end
claimed?()
click to toggle source
true if task is claimed
# File lib/bumbleworks/task.rb, line 157 def claimed? !claimant.nil? end
claimed_at()
click to toggle source
Timestamp of last claim, nil if not currently claimed
# File lib/bumbleworks/task.rb, line 144 def claimed_at params['claimed_at'] end
complete(metadata = {}, options = {})
click to toggle source
proceed workitem (saving changes to fields)
# File lib/bumbleworks/task.rb, line 126 def complete(metadata = {}, options = {}) unless completable? || options.fetch(:force, false) raise NotCompletable.new(not_completable_error_message) end with_hooks(:update, metadata, options) do with_hooks(:complete, metadata, options) do proceed_workitem log(:complete, metadata) end end end
extend_module()
click to toggle source
# File lib/bumbleworks/task.rb, line 89 def extend_module extend Bumbleworks::Task::Base begin extend task_module if nickname rescue NameError end end
humanize(options = {})
click to toggle source
# File lib/bumbleworks/task.rb, line 193 def humanize(options = {}) displayify(:humanize, options) end
log(action, metadata = {})
click to toggle source
# File lib/bumbleworks/task.rb, line 175 def log(action, metadata = {}) Bumbleworks.logger.info({ :actor => params['claimant'], :action => action, :target_type => 'Task', :target_id => id, :metadata => metadata.merge(:current_fields => fields) }) end
on_dispatch()
click to toggle source
# File lib/bumbleworks/task.rb, line 170 def on_dispatch log(:dispatch) call_after_hooks(:dispatch) end
release(options = {})
click to toggle source
release claim on task.
# File lib/bumbleworks/task.rb, line 162 def release(options = {}) current_claimant = claimant with_hooks(:release, current_claimant, options) do log(:release) set_claimant(nil) end end
reload()
click to toggle source
# File lib/bumbleworks/task.rb, line 70 def reload @workitem = storage_participant[sid] self end
role()
click to toggle source
# File lib/bumbleworks/task.rb, line 85 def role participant_name end
task_module()
click to toggle source
# File lib/bumbleworks/task.rb, line 97 def task_module return nil unless nickname klass_name = Bumbleworks::Support.camelize(nickname) klass = Bumbleworks::Support.constantize("#{klass_name}Task") end
temporary_storage()
click to toggle source
# File lib/bumbleworks/task.rb, line 21 def temporary_storage @temporary_storage ||= {} end
titleize(options = {})
click to toggle source
# File lib/bumbleworks/task.rb, line 189 def titleize(options = {}) displayify(:titleize, options) end
to_s(options = {})
click to toggle source
# File lib/bumbleworks/task.rb, line 185 def to_s(options = {}) titleize(options) end
update(metadata = {}, options = {})
click to toggle source
update workitem with changes to fields & params
# File lib/bumbleworks/task.rb, line 118 def update(metadata = {}, options = {}) with_hooks(:update, metadata, options) do update_workitem log(:update, metadata) end end
with_hooks(action, metadata, options = {}) { || ... }
click to toggle source
# File lib/bumbleworks/task.rb, line 111 def with_hooks(action, metadata, options = {}) call_before_hooks(action, metadata) unless options[:skip_callbacks] yield call_after_hooks(action, metadata) unless options[:skip_callbacks] end
Private Instance Methods
call_hooks(phase, action, *args)
click to toggle source
# File lib/bumbleworks/task.rb, line 198 def call_hooks(phase, action, *args) (Bumbleworks.observers + [self]).each do |observer| observer.send(:"#{phase}_#{action}", *args) end end
displayify(modifier, options = {})
click to toggle source
# File lib/bumbleworks/task.rb, line 204 def displayify(modifier, options = {}) task_name = Bumbleworks::Support.send(modifier, nickname) if options[:entity] != false && !(entity_fields = entity_fields(modifier => true)).empty? "#{task_name}: #{entity_fields[:type]} #{entity_fields[:identifier]}" else task_name end end
proceed_workitem()
click to toggle source
# File lib/bumbleworks/task.rb, line 223 def proceed_workitem storage_participant.proceed(@workitem) end
set_claimant(token)
click to toggle source
# File lib/bumbleworks/task.rb, line 227 def set_claimant(token) if token && claimant && token != claimant raise AlreadyClaimed, "Already claimed by #{claimant}" end params['claimant'] = token params['claimed_at'] = token ? Time.now : nil update_workitem end
storage_participant()
click to toggle source
# File lib/bumbleworks/task.rb, line 214 def storage_participant self.class.storage_participant end
update_workitem()
click to toggle source
# File lib/bumbleworks/task.rb, line 218 def update_workitem storage_participant.update(@workitem) reload end