Module: Bumbleworks::Entity
- Defined in:
- lib/bumbleworks/entity.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #attribute_for_process_name(name) ⇒ Object
- #cancel_all_processes!(options = {}) ⇒ Object
- #identifier ⇒ Object
- #is_waiting_for?(event) ⇒ Boolean
- #launch_process(process_name, options = {}) ⇒ Object
- #persist_process_identifier(identifier_attribute, process_identifier) ⇒ Object
- #process_fields(process_name = nil) ⇒ Object
- #process_variables(process_name = nil) ⇒ Object
- #processes ⇒ Object
- #processes_by_name ⇒ Object
- #subscribed_events ⇒ Object
- #tasks(nickname = nil) ⇒ Object
- #to_s ⇒ Object
Class Method Details
.included(klass) ⇒ Object
3 4 5 |
# File 'lib/bumbleworks/entity.rb', line 3 def self.included(klass) klass.extend ClassMethods end |
Instance Method Details
#attribute_for_process_name(name) ⇒ Object
59 60 61 |
# File 'lib/bumbleworks/entity.rb', line 59 def attribute_for_process_name(name) self.class.processes[name][:attribute] end |
#cancel_all_processes!(options = {}) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/bumbleworks/entity.rb', line 48 def cancel_all_processes!( = {}) processes_by_name.each do |name, process| next unless process process.cancel! unless [:clear_identifiers] == false identifier_attribute = attribute_for_process_name(name) persist_process_identifier(identifier_attribute, nil) end end end |
#identifier ⇒ Object
7 8 9 |
# File 'lib/bumbleworks/entity.rb', line 7 def identifier id end |
#is_waiting_for?(event) ⇒ Boolean
81 82 83 |
# File 'lib/bumbleworks/entity.rb', line 81 def is_waiting_for?(event) subscribed_events.include? event.to_s end |
#launch_process(process_name, options = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/bumbleworks/entity.rb', line 15 def launch_process(process_name, = {}) identifier_attribute = attribute_for_process_name(process_name.to_sym) if ([:force] == true || (process_identifier = self.send(identifier_attribute)).nil?) workitem_fields = process_fields(process_name.to_sym).merge([:fields] || {}) variables = process_variables(process_name.to_sym).merge([:variables] || {}) process_identifier = Bumbleworks.launch!(process_name.to_s, workitem_fields, variables).wfid persist_process_identifier(identifier_attribute.to_sym, process_identifier) end Bumbleworks::Process.new(process_identifier) end |
#persist_process_identifier(identifier_attribute, process_identifier) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/bumbleworks/entity.rb', line 26 def persist_process_identifier(identifier_attribute, process_identifier) if self.respond_to?(:update) update(identifier_attribute => process_identifier) else raise "Entity must define #persist_process_identifier method if missing #update method." end end |
#process_fields(process_name = nil) ⇒ Object
69 70 71 |
# File 'lib/bumbleworks/entity.rb', line 69 def process_fields(process_name = nil) { :entity => self } end |
#process_variables(process_name = nil) ⇒ Object
73 74 75 |
# File 'lib/bumbleworks/entity.rb', line 73 def process_variables(process_name = nil) {} end |
#processes ⇒ Object
44 45 46 |
# File 'lib/bumbleworks/entity.rb', line 44 def processes processes_by_name.values.compact end |
#processes_by_name ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/bumbleworks/entity.rb', line 34 def processes_by_name return {} unless self.class.processes process_names = self.class.processes.keys process_names.inject({}) do |memo, name| pid = self.send(attribute_for_process_name(name)) memo[name] = pid ? Bumbleworks::Process.new(pid) : nil memo end end |
#subscribed_events ⇒ Object
77 78 79 |
# File 'lib/bumbleworks/entity.rb', line 77 def subscribed_events processes.values.compact.map(&:subscribed_events).flatten.uniq end |
#tasks(nickname = nil) ⇒ Object
63 64 65 66 67 |
# File 'lib/bumbleworks/entity.rb', line 63 def tasks(nickname = nil) finder = Bumbleworks::Task.for_entity(self) finder = finder.by_nickname(nickname) if nickname finder end |
#to_s ⇒ Object
11 12 13 |
# File 'lib/bumbleworks/entity.rb', line 11 def to_s "#{Bumbleworks::Support.titleize(self.class.name)} #{identifier}" end |