Class: Dgrid::API::Item
Instance Attribute Summary collapse
Attributes inherited from NamedEntity
#name
Attributes inherited from Entity
#description, #id, #workspaces
Class Method Summary
collapse
Instance Method Summary
collapse
included
Methods inherited from Entity
#add_entity, #add_workspace, #attach, #connection, #first_workspace, #in_workspace?, #link_to, #new_record?, singular, #type, type
#change_string_keys_to_symbol_keys, #set_members_from_hash, #split_hash
Constructor Details
#initialize(options) ⇒ Item
Returns a new instance of Item.
10
11
12
13
14
15
16
|
# File 'lib/dgrid/api/item.rb', line 10
def initialize(options)
parent_opts, my_opts = split_hash(options,[:name, :description])
super(parent_opts)
set_members_from_hash(my_opts)
@body ||= ''
@incidents = nil
end
|
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
5
6
7
|
# File 'lib/dgrid/api/item.rb', line 5
def body
@body
end
|
Class Method Details
.db_fields ⇒ Object
18
19
20
|
# File 'lib/dgrid/api/item.rb', line 18
def self.db_fields
%w(id name body source)
end
|
.pluralized ⇒ Object
22
23
24
|
# File 'lib/dgrid/api/item.rb', line 22
def self.pluralized
'items'
end
|
Instance Method Details
#create_incident(options = {}) {|incident| ... } ⇒ Object
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/dgrid/api/item.rb', line 48
def create_incident(options = {}, &block)
incident = Dgrid::API::Incident.new(options)
workspaces.each do |workspace_id, workspace|
returned_incident = workspace.add_incident(incident)
incident = returned_incident if incident.new_record?
workspace.subordinate_entity_to_other_entity(incident,self)
end
yield incident if block_given?
incident
end
|
#incident_ids ⇒ Object
36
37
38
|
# File 'lib/dgrid/api/item.rb', line 36
def incident_ids
workspace.incident_ids_in_item(self)
end
|
#incidents ⇒ Object
40
41
42
43
44
45
|
# File 'lib/dgrid/api/item.rb', line 40
def incidents
incident_list = workspace.incidents
incident_hash = {}
incident_list.each { |incident| incident_hash[incident.id] = incident}
return incident_ids.map { |id| incident_hash[id]}
end
|
#to_hash ⇒ Object
26
27
28
29
30
|
# File 'lib/dgrid/api/item.rb', line 26
def to_hash
{ :name => name,
:body => body
}
end
|
#workspace ⇒ Object
32
33
34
|
# File 'lib/dgrid/api/item.rb', line 32
def workspace
workspace = workspaces.values.first end
|