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

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

Instance Method Summary collapse

Methods included from Persistence

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

Methods included from Persistence::PersistenceOptionable

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

Methods included from Optionable

#bitemporal_option, #bitemporal_option_merge!, #with_bitemporal_option

Instance Method Details

#bitemporal_id_keyObject



56
57
58
# File 'lib/activerecord-bitemporal/bitemporalize.rb', line 56

def bitemporal_id_key
  self.class.bitemporal_id_key
end

#bitemporal_ignore_update_columnsObject



60
61
62
# File 'lib/activerecord-bitemporal/bitemporalize.rb', line 60

def bitemporal_ignore_update_columns
  []
end

#id_in_databaseObject



64
65
66
# File 'lib/activerecord-bitemporal/bitemporalize.rb', line 64

def id_in_database
  swapped_id.presence || super
end

#previously_force_updated?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/activerecord-bitemporal/bitemporalize.rb', line 68

def previously_force_updated?
  @previously_force_updated
end

#swap_id!(without_clear_changes_information: false) ⇒ Object



41
42
43
44
45
46
# File 'lib/activerecord-bitemporal/bitemporalize.rb', line 41

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_idObject



48
49
50
# File 'lib/activerecord-bitemporal/bitemporalize.rb', line 48

def swapped_id
  @_swapped_id || self.id
end

#swapped_id_previously_wasObject



52
53
54
# File 'lib/activerecord-bitemporal/bitemporalize.rb', line 52

def swapped_id_previously_was
  @_swapped_id_previously_was
end

#transaction_from_cannot_be_greater_equal_than_transaction_toObject



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

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_toObject



72
73
74
75
76
# File 'lib/activerecord-bitemporal/bitemporalize.rb', line 72

def valid_from_cannot_be_greater_equal_than_valid_to
  if self[valid_from_key] && self[valid_to_key] && self[valid_from_key] >= self[valid_to_key]
    errors.add(valid_from_key, "can't be greater equal than #{valid_to_key}")
  end
end