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
52
|
# 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.class_name.constantize.history
send(
association.macro, association.name,
**association.options.merge(
class_name: clazz.name,
foreign_key: association.foreign_key,
primary_key: clazz.orig_class.primary_key
)
)
end
end
end
end
|
Instance Method Details
#next ⇒ Object
102
103
104
|
# File 'lib/temporal_tables/temporal_class.rb', line 102
def next
@next ||= history.where(self.class.arel_table[:eff_from].gt(eff_from)).first
end
|
#orig_class ⇒ Object
86
87
88
|
# File 'lib/temporal_tables/temporal_class.rb', line 86
def orig_class
self.class.orig_class
end
|
#orig_id ⇒ Object
90
91
92
|
# File 'lib/temporal_tables/temporal_class.rb', line 90
def orig_id
attributes[orig_class.primary_key]
end
|
#orig_obj ⇒ Object
94
95
96
|
# File 'lib/temporal_tables/temporal_class.rb', line 94
def orig_obj
@orig_obj ||= orig_class.find_by(orig_class.primary_key => orig_id)
end
|
#prev ⇒ Object
98
99
100
|
# File 'lib/temporal_tables/temporal_class.rb', line 98
def prev
@prev ||= history.where(self.class.arel_table[:eff_from].lt(eff_from)).last
end
|