Class: Bumbleworks::Workitem

Inherits:
Object
  • Object
show all
Defined in:
lib/bumbleworks/workitem.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_workitem) ⇒ Workitem

Returns a new instance of Workitem.



5
6
7
# File 'lib/bumbleworks/workitem.rb', line 5

def initialize(raw_workitem)
  @raw_workitem = raw_workitem
end

Instance Attribute Details

#raw_workitemObject (readonly)

Returns the value of attribute raw_workitem.



3
4
5
# File 'lib/bumbleworks/workitem.rb', line 3

def raw_workitem
  @raw_workitem
end

Instance Method Details

#==(other) ⇒ Object



9
10
11
# File 'lib/bumbleworks/workitem.rb', line 9

def ==(other)
  raw_workitem == other.raw_workitem
end

#entity(options = {}) ⇒ Object

Raises:



13
14
15
16
17
18
19
20
21
# File 'lib/bumbleworks/workitem.rb', line 13

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



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/bumbleworks/workitem.rb', line 33

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

#entity_nameObject



48
49
50
51
# File 'lib/bumbleworks/workitem.rb', line 48

def entity_name
  fields = entity_fields(:titleize => true)
  "#{fields[:type]} #{fields[:identifier]}"
end

#has_entity?Boolean

Returns:

  • (Boolean)


23
24
25
26
27
# File 'lib/bumbleworks/workitem.rb', line 23

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

#has_entity_fields?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/bumbleworks/workitem.rb', line 29

def has_entity_fields?
  entity_id && entity_type
end