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
4
5
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
|
# File 'lib/temporal_tables/temporal_class.rb', line 4
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
end
def self.temporalize_associations!
reflect_on_all_associations.dup.each do |association|
unless @@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
end
|
Instance Method Details
#next ⇒ Object
87
88
89
|
# File 'lib/temporal_tables/temporal_class.rb', line 87
def next
@next ||= history.where(self.class.arel_table[:eff_from].gt(eff_from)).first
end
|
#orig_class ⇒ Object
71
72
73
|
# File 'lib/temporal_tables/temporal_class.rb', line 71
def orig_class
self.class.orig_class
end
|
#orig_id ⇒ Object
75
76
77
|
# File 'lib/temporal_tables/temporal_class.rb', line 75
def orig_id
attributes[orig_class.primary_key]
end
|
#orig_obj ⇒ Object
79
80
81
|
# File 'lib/temporal_tables/temporal_class.rb', line 79
def orig_obj
@orig_obj ||= orig_class.find_by_id orig_id
end
|
#prev ⇒ Object
83
84
85
|
# File 'lib/temporal_tables/temporal_class.rb', line 83
def prev
@prev ||= history.where(self.class.arel_table[:eff_from].lt(eff_from)).last
end
|