Class: Indicator

Inherits:
Progress show all
Defined in:
app/models/indicator.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Progress

#dirty_parent_by_submission!, #parent

Methods inherited from ApplicationRecord

aggregate_of, all_except, defaults, #delete, #destroy!, numbered, organic_on, resource_fields, #save, #save_and_notify!, #save_and_notify_changes!, serialize_symbolized_hash_array, #update_and_notify!, update_or_create!, whitelist_attributes

Class Method Details

.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
# File 'app/models/indicator.rb', line 37

def clean!
  self.dirty_by_submission = false
  self.dirty_by_content_change = false
end

#completed?Boolean

Returns:

  • (Boolean)


55
56
57
58
# File 'app/models/indicator.rb', line 55

def completed?
  rebuild!
  children_passed_count == children_count
end

#completion_percentageObject



50
51
52
53
# File 'app/models/indicator.rb', line 50

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

#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



42
43
44
# File 'app/models/indicator.rb', line 42

def refresh_children_count!
  self.children_count = content.structural_children.count
end

#refresh_children_passed_count!Object



46
47
48
# File 'app/models/indicator.rb', line 46

def refresh_children_passed_count!
  self.children_passed_count = children.count(&:completed?)
end