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
- #cancel_process!(process_name, 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 6 7 8 |
# File 'lib/bumbleworks/entity.rb', line 3 def self.included(klass) unless Bumbleworks.entity_classes.include? klass Bumbleworks.entity_classes << klass end klass.extend ClassMethods end |
Instance Method Details
#attribute_for_process_name(name) ⇒ Object
67 68 69 |
# File 'lib/bumbleworks/entity.rb', line 67 def attribute_for_process_name(name) self.class.processes[name][:attribute] end |
#cancel_all_processes!(options = {}) ⇒ Object
61 62 63 64 65 |
# File 'lib/bumbleworks/entity.rb', line 61 def cancel_all_processes!( = {}) processes_by_name.keys.each do |process_name| cancel_process!(process_name, ) end end |
#cancel_process!(process_name, options = {}) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/bumbleworks/entity.rb', line 51 def cancel_process!(process_name, = {}) process = processes_by_name[process_name.to_sym] return nil unless process process.cancel! unless [:clear_identifiers] == false identifier_attribute = attribute_for_process_name(process_name.to_sym) persist_process_identifier(identifier_attribute, nil) end end |
#identifier ⇒ Object
10 11 12 |
# File 'lib/bumbleworks/entity.rb', line 10 def identifier id end |
#is_waiting_for?(event) ⇒ Boolean
89 90 91 |
# File 'lib/bumbleworks/entity.rb', line 89 def is_waiting_for?(event) subscribed_events.include? event.to_s end |
#launch_process(process_name, options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/bumbleworks/entity.rb', line 18 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
29 30 31 32 33 34 35 |
# File 'lib/bumbleworks/entity.rb', line 29 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
77 78 79 |
# File 'lib/bumbleworks/entity.rb', line 77 def process_fields(process_name = nil) { :entity => self } end |
#process_variables(process_name = nil) ⇒ Object
81 82 83 |
# File 'lib/bumbleworks/entity.rb', line 81 def process_variables(process_name = nil) {} end |
#processes ⇒ Object
47 48 49 |
# File 'lib/bumbleworks/entity.rb', line 47 def processes processes_by_name.values.compact end |
#processes_by_name ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/bumbleworks/entity.rb', line 37 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
85 86 87 |
# File 'lib/bumbleworks/entity.rb', line 85 def subscribed_events processes.values.compact.map(&:subscribed_events).flatten.uniq end |
#tasks(nickname = nil) ⇒ Object
71 72 73 74 75 |
# File 'lib/bumbleworks/entity.rb', line 71 def tasks(nickname = nil) finder = Bumbleworks::Task.for_entity(self) finder = finder.by_nickname(nickname) if nickname finder end |
#to_s ⇒ Object
14 15 16 |
# File 'lib/bumbleworks/entity.rb', line 14 def to_s "#{Bumbleworks::Support.titleize(self.class.name)} #{identifier}" end |