class Bumbleworks::Workitem

Attributes

raw_workitem[R]

Public Class Methods

new(raw_workitem) click to toggle source
# File lib/bumbleworks/workitem.rb, line 9
def initialize(raw_workitem)
  @raw_workitem = raw_workitem
end

Public Instance Methods

entity(options = {}) click to toggle source
# File lib/bumbleworks/workitem.rb, line 17
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 = {}) click to toggle source
# File lib/bumbleworks/workitem.rb, line 37
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_name() click to toggle source
# File lib/bumbleworks/workitem.rb, line 56
def entity_name
  fields = entity_fields(:titleize => true)
  "#{fields[:type]} #{fields[:identifier]}"
end
has_entity?() click to toggle source
# File lib/bumbleworks/workitem.rb, line 27
def has_entity?
  !entity.nil?
rescue EntityNotFound
  false
end
has_entity_fields?() click to toggle source
# File lib/bumbleworks/workitem.rb, line 33
def has_entity_fields?
  entity_id && entity_type
end
identifier_for_comparison() click to toggle source
# File lib/bumbleworks/workitem.rb, line 13
def identifier_for_comparison
  raw_workitem
end
tokenized_entity_type() click to toggle source
# File lib/bumbleworks/workitem.rb, line 52
def tokenized_entity_type
  Bumbleworks::Support.tokenize(entity_type)
end

Private Instance Methods

entity_id() click to toggle source
# File lib/bumbleworks/workitem.rb, line 63
def entity_id
  @raw_workitem.fields[:entity_id] || @raw_workitem.fields['entity_id']
end
entity_type() click to toggle source
# File lib/bumbleworks/workitem.rb, line 67
def entity_type
  @raw_workitem.fields[:entity_type] || @raw_workitem.fields['entity_type']
end