Module: Bumbleworks::WorkitemEntityStorage

Included in:
ErrorHandler, LocalParticipant, Task
Defined in:
lib/bumbleworks/workitem_entity_storage.rb

Defined Under Namespace

Classes: EntityNotFound

Instance Method Summary collapse

Instance Method Details

#entity(options = {}) ⇒ Object

Raises:



5
6
7
8
9
10
11
12
13
# File 'lib/bumbleworks/workitem_entity_storage.rb', line 5

def entity(options = {})
  @entity = nil if options[:reload] == true
  @entity ||= if has_entity_fields?
    klass = Bumbleworks::Support.constantize(entity_type)
    entity = klass.first_by_identifier(entity_id)
  end
  raise EntityNotFound, {:entity_id => entity_id, :entity_type => entity_type} unless @entity
  @entity
end

#entity_fields(options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/bumbleworks/workitem_entity_storage.rb', line 25

def entity_fields(options = {})
  return {} unless has_entity_fields?
  type = if options[:humanize] == true
    Bumbleworks::Support.humanize(entity_type)
  elsif options[:titleize] == true
    Bumbleworks::Support.titleize(entity_type)
  else
    entity_type
  end
  {
    :type => type,
    :identifier => entity_id
  }
end

#has_entity?Boolean

Returns:

  • (Boolean)


15
16
17
18
19
# File 'lib/bumbleworks/workitem_entity_storage.rb', line 15

def has_entity?
  !entity.nil?
rescue EntityNotFound
  false
end

#has_entity_fields?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/bumbleworks/workitem_entity_storage.rb', line 21

def has_entity_fields?
  entity_id && entity_type
end