Module: TimeTravel::TimelineHelper

Extended by:
ActiveSupport::Concern
Defined in:
lib/time_travel/timeline_helper.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#absence_of_valid_from_tillObject



78
79
80
81
82
# File 'lib/time_travel/timeline_helper.rb', line 78

def absence_of_valid_from_till
  if self.valid_from.present? || self.valid_till.present?
    self.errors.add(:base, "valid_from and valid_till can't be set")
  end
end

#effective_now?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/time_travel/timeline_helper.rb', line 101

def effective_now?
  self.effective_from.present? and self.effective_till==TimeTravel::INFINITE_DATE
end

#effective_range_timelineObject

validations



72
73
74
75
76
# File 'lib/time_travel/timeline_helper.rb', line 72

def effective_range_timeline
  if self.effective_from > self.effective_till
    self.errors.add(:base, "effective_from can't be greater than effective_till")
  end
end

#has_historyObject



59
60
61
62
63
# File 'lib/time_travel/timeline_helper.rb', line 59

def has_history
  if self.class.has_history?
    self.errors.add("base", "create called on alread existing timeline")
  end
end

#ineffective_now?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/time_travel/timeline_helper.rb', line 97

def ineffective_now?
  !self.effective_now?
end

#invalid_now?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/time_travel/timeline_helper.rb', line 89

def invalid_now?
  !self.valid_now?
end

#no_historyObject



65
66
67
68
69
# File 'lib/time_travel/timeline_helper.rb', line 65

def no_history
  if not self.class.has_history?
    self.errors.add("base", "update called on timeline that doesn't exist")
  end
end

#set_current_timeObject

set defaults



45
46
47
# File 'lib/time_travel/timeline_helper.rb', line 45

def set_current_time
  self.current_time ||= Time.current
end

#set_effective_defaultsObject



49
50
51
52
# File 'lib/time_travel/timeline_helper.rb', line 49

def set_effective_defaults
  self.effective_from ||= current_time
  self.effective_till ||= TimeTravel::INFINITE_DATE
end

#set_validity_defaultsObject



54
55
56
57
# File 'lib/time_travel/timeline_helper.rb', line 54

def set_validity_defaults
  self.valid_from ||= current_time
  self.valid_till ||= TimeTravel::INFINITE_DATE
end

#valid_now?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/time_travel/timeline_helper.rb', line 93

def valid_now?
  self.valid_from.present? and self.valid_till==TimeTravel::INFINITE_DATE
end

#validate_update(attributes) ⇒ Object



84
85
86
87
# File 'lib/time_travel/timeline_helper.rb', line 84

def validate_update(attributes)
  self.assign_attributes(attributes)
  self.valid?
end