Module: TemporalTables::TemporalClass
- Defined in:
- lib/temporal_tables/temporal_class.rb
Overview
This is mixed into all History classes.
Defined Under Namespace
Modules: ClassMethods, STIWithHistory
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.included(base) ⇒ Object
rubocop:disable Metrics/MethodLength, Metrics/AbcSize
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/temporal_tables/temporal_class.rb', line 6
def self.included(base) base.class_eval do
base.extend ClassMethods
self.table_name += '_h'
cattr_accessor :visited_associations
@visited_associations = []
attr_accessor :at_value
class << self
prepend STIWithHistory
delegate :at, to: :all
end
def self.temporalize_associations! reflect_on_all_associations.dup.each do |association|
next if @visited_associations.include?(association.name) || association.options[:polymorphic]
@visited_associations << association.name
clazz = association.klass.history
send(
association.macro, association.name,
**association.options.merge(
class_name: clazz.name,
foreign_key: association.foreign_key
)
)
end
end
end
end
|
Instance Method Details
#next ⇒ Object
101
102
103
|
# File 'lib/temporal_tables/temporal_class.rb', line 101
def next
@next ||= history.where(self.class.arel_table[:eff_from].gt(eff_from)).first
end
|
#orig_class ⇒ Object
85
86
87
|
# File 'lib/temporal_tables/temporal_class.rb', line 85
def orig_class
self.class.orig_class
end
|
#orig_id ⇒ Object
89
90
91
|
# File 'lib/temporal_tables/temporal_class.rb', line 89
def orig_id
attributes[orig_class.primary_key]
end
|
#orig_obj ⇒ Object
93
94
95
|
# File 'lib/temporal_tables/temporal_class.rb', line 93
def orig_obj
@orig_obj ||= orig_class.find_by(orig_class.primary_key => orig_id)
end
|
#prev ⇒ Object
97
98
99
|
# File 'lib/temporal_tables/temporal_class.rb', line 97
def prev
@prev ||= history.where(self.class.arel_table[:eff_from].lt(eff_from)).last
end
|