Module: ActiveRecord::Bitemporal::Bitemporalize::InstanceMethods

Includes:
Persistence
Defined in:
lib/activerecord-bitemporal.rb

Instance Method Summary collapse

Methods included from Persistence

#_create_record, #_update_row, #destroy, #save, #save!

Methods included from Persistence::PersistenceOptionable

#bitemporal_option_merge_with_association!, #force_update, #force_update?, #transaction_at, #transaction_datetime, #valid_at, #valid_datetime

Methods included from Optionable

#bitemporal_option, #bitemporal_option_merge!, #with_bitemporal_option

Instance Method Details

#bitemporal_id_key ⇒ Object



93
94
95
# File 'lib/activerecord-bitemporal.rb', line 93

def bitemporal_id_key
  self.class.bitemporal_id_key
end

#bitemporal_ignore_update_columns ⇒ Object



97
98
99
# File 'lib/activerecord-bitemporal.rb', line 97

def bitemporal_ignore_update_columns
  []
end

#id_in_database ⇒ Object



101
102
103
# File 'lib/activerecord-bitemporal.rb', line 101

def id_in_database
  swapped_id.presence || super
end

#swap_id!(without_clear_changes_information: false) ⇒ Object



78
79
80
81
82
83
# File 'lib/activerecord-bitemporal.rb', line 78

def swap_id!(without_clear_changes_information: false)
  @_swapped_id_previously_was = nil
  @_swapped_id = self.id
  self.id = self.send(bitemporal_id_key)
  clear_attribute_changes([:id]) unless without_clear_changes_information
end

#swapped_id ⇒ Object



85
86
87
# File 'lib/activerecord-bitemporal.rb', line 85

def swapped_id
  @_swapped_id || self.id
end

#swapped_id_previously_was ⇒ Object



89
90
91
# File 'lib/activerecord-bitemporal.rb', line 89

def swapped_id_previously_was
  @_swapped_id_previously_was
end

#transaction_from_cannot_be_greater_equal_than_transaction_to ⇒ Object



111
112
113
114
115
# File 'lib/activerecord-bitemporal.rb', line 111

def transaction_from_cannot_be_greater_equal_than_transaction_to
  if transaction_from && transaction_to && transaction_from >= transaction_to
    errors.add(:transaction_from, "can't be greater equal than transaction_to")
  end
end

#valid_from_cannot_be_greater_equal_than_valid_to ⇒ Object



105
106
107
108
109
# File 'lib/activerecord-bitemporal.rb', line 105

def valid_from_cannot_be_greater_equal_than_valid_to
  if valid_from && valid_to && valid_from >= valid_to
    errors.add(:valid_from, "can't be greater equal than valid_to")
  end
end