module PeriodicRecords::Gapless
Private Instance Methods
adjust_gaps()
click to toggle source
# File lib/periodic_records/gapless.rb, line 31 def adjust_gaps adjust_previous_gap adjust_next_gap end
adjust_next_gap()
click to toggle source
# File lib/periodic_records/gapless.rb, line 46 def adjust_next_gap if saved_change_to_end_at? && end_at && end_at_before_last_save && end_at_before_last_save > end_at next_record = siblings.where(start_at: end_at_before_last_save + 1.day).first if next_record next_record.start_at = end_at + 1.day next_record.save(validate: false) end end end
adjust_previous_gap()
click to toggle source
# File lib/periodic_records/gapless.rb, line 36 def adjust_previous_gap if saved_change_to_start_at? && start_at && start_at_before_last_save && start_at > start_at_before_last_save previous_record = siblings.where(end_at: start_at_before_last_save - 1.day).first if previous_record previous_record.end_at = start_at - 1.day previous_record.save(validate: false) end end end
after_gapless_destroy()
click to toggle source
# File lib/periodic_records/gapless.rb, line 68 def after_gapless_destroy previous_record = siblings.where(end_at: start_at - 1.day).first if previous_record previous_record.end_at = end_at previous_record.save(validate: false) end end
before_gapless_destroy()
click to toggle source
# File lib/periodic_records/gapless.rb, line 56 def before_gapless_destroy if start_at == self.class::MIN errors.add :start_at, :invalid end if end_at == self.class::MAX errors.add :end_at, :invalid end unless errors.empty? throw :abort end end
gapless?()
click to toggle source
# File lib/periodic_records/gapless.rb, line 15 def gapless? true end
validate_gapless_end_at()
click to toggle source
# File lib/periodic_records/gapless.rb, line 25 def validate_gapless_end_at if end_at_changed? && end_at_was == self.class::MAX errors.add :end_at, :invalid end end
validate_gapless_start_at()
click to toggle source
# File lib/periodic_records/gapless.rb, line 19 def validate_gapless_start_at if start_at_changed? && start_at_was == self.class::MIN errors.add :start_at, :invalid end end