Module: ActiveRecord::Bitemporal::Relation
- Includes:
- Finder
- Defined in:
- lib/activerecord-bitemporal/bitemporal.rb,
lib/activerecord-bitemporal/scope.rb
Defined Under Namespace
Modules: Finder, MergeWithExceptBitemporalDefaultScope
Classes: WhereClauseWithCheckTable
Instance Method Summary
collapse
Methods included from Finder
#find, #find_at_time, #find_at_time!
Instance Method Details
#bitemporal_option ⇒ Object
173
174
175
|
# File 'lib/activerecord-bitemporal/scope.rb', line 173
def bitemporal_option
::ActiveRecord::Bitemporal.merge_by(bitemporal_value.merge bitemporal_clause)
end
|
#bitemporal_option_merge!(other) ⇒ Object
177
178
179
|
# File 'lib/activerecord-bitemporal/scope.rb', line 177
def bitemporal_option_merge!(other)
self.bitemporal_value = bitemporal_value.merge other
end
|
#bitemporal_value ⇒ Object
181
182
183
|
# File 'lib/activerecord-bitemporal/scope.rb', line 181
def bitemporal_value
@values[:bitemporal_value] ||= {}
end
|
#bitemporal_value=(value) ⇒ Object
185
186
187
|
# File 'lib/activerecord-bitemporal/scope.rb', line 185
def bitemporal_value=(value)
@values[:bitemporal_value] = value
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
169
170
171
|
# File 'lib/activerecord-bitemporal/scope.rb', line 169
def transaction_datetime
bitemporal_clause[:transaction_datetime]&.in_time_zone
end
|
#valid_datetime ⇒ Object
165
166
167
|
# File 'lib/activerecord-bitemporal/scope.rb', line 165
def valid_datetime
bitemporal_clause[:valid_datetime]&.in_time_zone
end
|
#where_clause ⇒ Object
149
150
151
|
# File 'lib/activerecord-bitemporal/scope.rb', line 149
def where_clause
WhereClauseWithCheckTable.new(super.send(:predicates))
end
|