Module: RoadToElDuration::Calculations

Extended by:
ActiveSupport::Concern
Defined in:
lib/road_to_el_duration/calculations.rb

Instance Method Summary collapse

Instance Method Details

#update_any_parent_durationsObject

This method is used to update the duration of the parent records. It will only update the parent records if the parent_to_update attribute is set. It will update the duration of the current parent record and any previous parent record if the record was transferred or removed from the collection.



59
60
61
62
# File 'lib/road_to_el_duration/calculations.rb', line 59

def update_any_parent_durations
  update_previous_parent_duration if transferred_or_removed_from_collection?
  update_current_parent_duration if has_parent_record?
end

#update_duration!Object

This method is used to update the duration of the record. It will sum the :duration_column of the associated records and update the :duration_column of the record. It is left as public API so that you can call it manually if needed.



48
49
50
51
52
# File 'lib/road_to_el_duration/calculations.rb', line 48

def update_duration!
  child_class = ActiveSupport::Inflector.singularize(child_association_name).camelize.constantize
  duration_value[child_class.parent_duration_column] = calculate_duration
  update!(**duration_value)
end