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
127
128
129
|
# File 'lib/activerecord-bitemporal/scope.rb', line 127
def bitemporal_option
::ActiveRecord::Bitemporal.merge_by(bitemporal_value.merge bitemporal_clause)
end
|
#bitemporal_option_merge!(other) ⇒ Object
131
132
133
|
# File 'lib/activerecord-bitemporal/scope.rb', line 131
def bitemporal_option_merge!(other)
self.bitemporal_value = bitemporal_value.merge other
end
|
#bitemporal_value ⇒ Object
135
136
137
|
# File 'lib/activerecord-bitemporal/scope.rb', line 135
def bitemporal_value
@values[:bitemporal_value] ||= {}
end
|
#bitemporal_value=(value) ⇒ Object
139
140
141
|
# File 'lib/activerecord-bitemporal/scope.rb', line 139
def bitemporal_value=(value)
@values[:bitemporal_value] = value
end
|
#build_arel ⇒ Object
151
152
153
154
155
|
# File 'lib/activerecord-bitemporal/bitemporal.rb', line 151
def build_arel(*)
ActiveRecord::Bitemporal.with_bitemporal_option(**bitemporal_option) {
super
}
end
|
#load ⇒ Object
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
# File 'lib/activerecord-bitemporal/bitemporal.rb', line 157
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
183
184
185
|
# File 'lib/activerecord-bitemporal/bitemporal.rb', line 183
def primary_key
bitemporal_id_key
end
|
#transaction_datetime ⇒ Object
123
124
125
|
# File 'lib/activerecord-bitemporal/scope.rb', line 123
def transaction_datetime
bitemporal_clause[:transaction_datetime]&.in_time_zone
end
|
#valid_date ⇒ Object
119
120
121
|
# File 'lib/activerecord-bitemporal/scope.rb', line 119
def valid_date
valid_datetime&.to_date
end
|
#valid_datetime ⇒ Object
115
116
117
|
# File 'lib/activerecord-bitemporal/scope.rb', line 115
def valid_datetime
bitemporal_clause[:valid_datetime]&.in_time_zone
end
|