Class: Indicator
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Progress
#dirty_parent_by_submission!, #parent
aggregate_of, all_except, defaults, #delete, #destroy!, numbered, organic_on, resource_fields, #save, #save_and_notify!, #save_and_notify_changes!, serialize_symbolized_hash_array, teaser_on, #update_and_notify!, update_or_create!, whitelist_attributes
Class Method Details
.delete_all_for!(content, organization) ⇒ Object
65
66
67
|
# File 'app/models/indicator.rb', line 65
def self.delete_all_for!(content, organization)
where(content: content, organization: organization).delete_all
end
|
.dirty_by_content_change!(content) ⇒ Object
14
15
16
|
# File 'app/models/indicator.rb', line 14
def self.dirty_by_content_change!(content)
where(content: content).update_all dirty_by_content_change: true
end
|
Instance Method Details
#clean! ⇒ Object
37
38
39
40
41
|
# File 'app/models/indicator.rb', line 37
def clean!
self.dirty_by_submission = false
self.dirty_by_content_change = false
self.once_completed ||= all_children_passed?
end
|
#completed? ⇒ Boolean
56
57
58
59
|
# File 'app/models/indicator.rb', line 56
def completed?
rebuild!
all_children_passed?
end
|
#completion_percentage ⇒ Object
51
52
53
54
|
# File 'app/models/indicator.rb', line 51
def completion_percentage
rebuild!
children_passed_count.fdiv children_count
end
|
#dirty_by_submission! ⇒ Object
18
19
20
|
# File 'app/models/indicator.rb', line 18
def dirty_by_submission!
propagate_up! { update! dirty_by_submission: true }
end
|
#once_completed? ⇒ Boolean
61
62
63
|
# File 'app/models/indicator.rb', line 61
def once_completed?
self.once_completed || completed?
end
|
#propagate_up!(&block) ⇒ Object
9
10
11
12
|
# File 'app/models/indicator.rb', line 9
def propagate_up!(&block)
instance_eval &block
parent&.instance_eval { propagate_up! &block }
end
|
#rebuild! ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'app/models/indicator.rb', line 22
def rebuild!
if dirty_by_content_change?
propagate_up! do
refresh_children_count!
refresh_children_passed_count!
clean!
save!
end
elsif dirty_by_submission?
refresh_children_passed_count!
clean!
save!
end
end
|
#refresh_children_count! ⇒ Object
43
44
45
|
# File 'app/models/indicator.rb', line 43
def refresh_children_count!
self.children_count = content.structural_children.count
end
|
#refresh_children_passed_count! ⇒ Object
47
48
49
|
# File 'app/models/indicator.rb', line 47
def refresh_children_passed_count!
self.children_passed_count = children.count(&:completed?)
end
|