Module: Bumbleworks::Entity
- Defined in:
- lib/bumbleworks/entity.rb
Defined Under Namespace
Modules: ClassMethods
Classes: ProcessNotRegistered
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.included(klass) ⇒ Object
5
6
7
8
9
10
|
# File 'lib/bumbleworks/entity.rb', line 5
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
72
73
74
75
76
|
# File 'lib/bumbleworks/entity.rb', line 72
def attribute_for_process_name(name)
process_config = self.class.processes[name]
raise ProcessNotRegistered.new(name) unless process_config
process_config && process_config[:attribute]
end
|
#cancel_all_processes!(options = {}) ⇒ Object
66
67
68
69
70
|
# File 'lib/bumbleworks/entity.rb', line 66
def cancel_all_processes!(options = {})
processes_by_name.keys.each do |process_name|
cancel_process!(process_name, options)
end
end
|
#cancel_process!(process_name, options = {}) ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/bumbleworks/entity.rb', line 53
def cancel_process!(process_name, options = {})
process = processes_by_name[process_name.to_sym]
return nil unless process
options = options.dup
clear_identifiers = options.delete(:clear_identifiers)
process.cancel!(options)
unless clear_identifiers == false
identifier_attribute = attribute_for_process_name(process_name.to_sym)
persist_process_identifier(identifier_attribute, nil)
end
end
|
#identifier ⇒ Object
12
13
14
|
# File 'lib/bumbleworks/entity.rb', line 12
def identifier
id
end
|
#is_waiting_for?(event) ⇒ Boolean
96
97
98
|
# File 'lib/bumbleworks/entity.rb', line 96
def is_waiting_for?(event)
subscribed_events.include? event.to_s
end
|
#launch_process(process_name, options = {}) ⇒ Object
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/bumbleworks/entity.rb', line 20
def launch_process(process_name, options = {})
identifier_attribute = attribute_for_process_name(process_name.to_sym)
if (options[:force] == true || (process_identifier = self.send(identifier_attribute)).nil?)
workitem_fields = process_fields(process_name.to_sym).merge(options[:fields] || {})
variables = process_variables(process_name.to_sym).merge(options[: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
31
32
33
34
35
36
37
|
# File 'lib/bumbleworks/entity.rb', line 31
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
84
85
86
|
# File 'lib/bumbleworks/entity.rb', line 84
def process_fields(process_name = nil)
{ :entity => self }
end
|
#process_variables(process_name = nil) ⇒ Object
88
89
90
|
# File 'lib/bumbleworks/entity.rb', line 88
def process_variables(process_name = nil)
{}
end
|
#processes ⇒ Object
49
50
51
|
# File 'lib/bumbleworks/entity.rb', line 49
def processes
processes_by_name.values.compact
end
|
#processes_by_name ⇒ Object
39
40
41
42
43
44
45
46
47
|
# File 'lib/bumbleworks/entity.rb', line 39
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
92
93
94
|
# File 'lib/bumbleworks/entity.rb', line 92
def subscribed_events
processes.values.compact.map(&:subscribed_events).flatten.uniq
end
|
#tasks(nickname = nil) ⇒ Object
78
79
80
81
82
|
# File 'lib/bumbleworks/entity.rb', line 78
def tasks(nickname = nil)
finder = Bumbleworks::Task.for_entity(self)
finder = finder.by_nickname(nickname) if nickname
finder
end
|
#to_s ⇒ Object
16
17
18
|
# File 'lib/bumbleworks/entity.rb', line 16
def to_s
"#{Bumbleworks::Support.titleize(self.class.name)} #{identifier}"
end
|