Class: Bumbleworks::Workitem
- Inherits:
-
Object
- Object
- Bumbleworks::Workitem
- Extended by:
- Forwardable
- Includes:
- Support::WrapperComparison
- Defined in:
- lib/bumbleworks/workitem.rb
Instance Attribute Summary collapse
-
#raw_workitem ⇒ Object
readonly
Returns the value of attribute raw_workitem.
Instance Method Summary collapse
- #entity(options = {}) ⇒ Object
- #entity_fields(options = {}) ⇒ Object
- #entity_name ⇒ Object
- #has_entity? ⇒ Boolean
- #has_entity_fields? ⇒ Boolean
- #identifier_for_comparison ⇒ Object
-
#initialize(raw_workitem) ⇒ Workitem
constructor
A new instance of Workitem.
- #tokenized_entity_type ⇒ Object
Methods included from Support::WrapperComparison
Constructor Details
#initialize(raw_workitem) ⇒ Workitem
Returns a new instance of Workitem.
9 10 11 |
# File 'lib/bumbleworks/workitem.rb', line 9 def initialize(raw_workitem) @raw_workitem = raw_workitem end |
Instance Attribute Details
#raw_workitem ⇒ Object (readonly)
Returns the value of attribute raw_workitem.
5 6 7 |
# File 'lib/bumbleworks/workitem.rb', line 5 def raw_workitem @raw_workitem end |
Instance Method Details
#entity(options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/bumbleworks/workitem.rb', line 17 def entity( = {}) @entity = nil if [: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
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/bumbleworks/workitem.rb', line 37 def entity_fields( = {}) return {} unless has_entity_fields? type = if [:humanize] == true Bumbleworks::Support.humanize(entity_type) elsif [:titleize] == true Bumbleworks::Support.titleize(entity_type) else entity_type end { :type => type, :identifier => entity_id } end |
#entity_name ⇒ Object
56 57 58 59 |
# File 'lib/bumbleworks/workitem.rb', line 56 def entity_name fields = entity_fields(:titleize => true) "#{fields[:type]} #{fields[:identifier]}" end |
#has_entity? ⇒ Boolean
27 28 29 30 31 |
# File 'lib/bumbleworks/workitem.rb', line 27 def has_entity? !entity.nil? rescue EntityNotFound false end |
#has_entity_fields? ⇒ Boolean
33 34 35 |
# File 'lib/bumbleworks/workitem.rb', line 33 def has_entity_fields? entity_id && entity_type end |
#identifier_for_comparison ⇒ Object
13 14 15 |
# File 'lib/bumbleworks/workitem.rb', line 13 def identifier_for_comparison raw_workitem end |
#tokenized_entity_type ⇒ Object
52 53 54 |
# File 'lib/bumbleworks/workitem.rb', line 52 def tokenized_entity_type Bumbleworks::Support.tokenize(entity_type) end |