Module: ActiveRecord::Bitemporal::Relation
- Includes:
- Finder
- Defined in:
- lib/activerecord-bitemporal/bitemporal.rb,
lib/activerecord-bitemporal/scope.rb
Defined Under Namespace
Modules: Finder, MergeWithExceptBitemporalDefaultScope
Instance Method Summary
collapse
Methods included from Finder
#find, #find_at_time, #find_at_time!
Instance Method Details
#bitemporal_option ⇒ Object
133
134
135
|
# File 'lib/activerecord-bitemporal/scope.rb', line 133
def bitemporal_option
::ActiveRecord::Bitemporal.merge_by(bitemporal_value.merge bitemporal_clause)
end
|
#bitemporal_option_merge!(other) ⇒ Object
137
138
139
|
# File 'lib/activerecord-bitemporal/scope.rb', line 137
def bitemporal_option_merge!(other)
self.bitemporal_value = bitemporal_value.merge other
end
|
#bitemporal_value ⇒ Object
141
142
143
|
# File 'lib/activerecord-bitemporal/scope.rb', line 141
def bitemporal_value
@values[:bitemporal_value] ||= {}
end
|
#bitemporal_value=(value) ⇒ Object
145
146
147
|
# File 'lib/activerecord-bitemporal/scope.rb', line 145
def bitemporal_value=(value)
@values[:bitemporal_value] = value
end
|
#build_arel ⇒ Object
139
140
141
142
143
|
# File 'lib/activerecord-bitemporal/bitemporal.rb', line 139
def build_arel(*)
ActiveRecord::Bitemporal.with_bitemporal_option(**bitemporal_option) {
super
}
end
|
#load ⇒ Object
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
# File 'lib/activerecord-bitemporal/bitemporal.rb', line 145
def load
return super if loaded?
records = ActiveRecord::Bitemporal.with_bitemporal_option(**bitemporal_option) { super }
return records if records.empty?
valid_datetime_ = valid_datetime
if ActiveRecord::Bitemporal.valid_datetime.nil? && (bitemporal_value[:with_valid_datetime].nil? || bitemporal_value[:with_valid_datetime] == :default_scope || valid_datetime_.nil?)
valid_datetime_ = nil
end
transaction_datetime_ = transaction_datetime
if ActiveRecord::Bitemporal.transaction_datetime.nil? && (bitemporal_value[:with_transaction_datetime].nil? || bitemporal_value[:with_transaction_datetime] == :default_scope || transaction_datetime_.nil?)
transaction_datetime_ = nil
end
return records if valid_datetime_.nil? && transaction_datetime_.nil?
records.each do |record|
record.send(:bitemporal_option_storage)[:valid_datetime] = valid_datetime_ if valid_datetime_
record.send(:bitemporal_option_storage)[:transaction_datetime] = transaction_datetime_ if transaction_datetime_
end
end
|
#primary_key ⇒ Object
171
172
173
|
# File 'lib/activerecord-bitemporal/bitemporal.rb', line 171
def primary_key
bitemporal_id_key
end
|
#transaction_datetime ⇒ Object
129
130
131
|
# File 'lib/activerecord-bitemporal/scope.rb', line 129
def transaction_datetime
bitemporal_clause[:transaction_datetime]&.in_time_zone
end
|
#valid_date ⇒ Object
125
126
127
|
# File 'lib/activerecord-bitemporal/scope.rb', line 125
def valid_date
valid_datetime&.to_date
end
|
#valid_datetime ⇒ Object
121
122
123
|
# File 'lib/activerecord-bitemporal/scope.rb', line 121
def valid_datetime
bitemporal_clause[:valid_datetime]&.in_time_zone
end
|