Module: ChronoModel::TimeMachine::HistoryModel
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/chrono_model/time_machine/history_model.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#current_version ⇒ Object
Returns this history entry’s current record.
-
#first ⇒ Object
Returns the first history entry.
- #historical? ⇒ Boolean
-
#id ⇒ Object
The history id is
hid, but this cannot set as primary key or temporal assocations will break. -
#last ⇒ Object
Returns the last history entry.
-
#pred ⇒ Object
Returns the previous history entry, or nil if this is the first one.
-
#record ⇒ Object
:nodoc:.
- #recorded_at ⇒ Object
-
#rid ⇒ Object
Referenced record ID.
- #save ⇒ Object
- #save! ⇒ Object
-
#succ ⇒ Object
(also: #next)
Returns the next history entry, or nil if this is the last one.
- #update_columns ⇒ Object
- #valid_from ⇒ Object
- #valid_to ⇒ Object (also: #as_of_time)
Instance Method Details
#current_version ⇒ Object
Returns this history entry’s current record
193 194 195 |
# File 'lib/chrono_model/time_machine/history_model.rb', line 193 def current_version self.class.superclass.find(rid) end |
#first ⇒ Object
Returns the first history entry
181 182 183 |
# File 'lib/chrono_model/time_machine/history_model.rb', line 181 def first self.class.where(id: rid).chronological.first end |
#historical? ⇒ Boolean
148 149 150 |
# File 'lib/chrono_model/time_machine/history_model.rb', line 148 def historical? true end |
#id ⇒ Object
The history id is hid, but this cannot set as primary key or temporal assocations will break. Solutions are welcome.
126 127 128 |
# File 'lib/chrono_model/time_machine/history_model.rb', line 126 def id hid end |
#last ⇒ Object
Returns the last history entry
187 188 189 |
# File 'lib/chrono_model/time_machine/history_model.rb', line 187 def last self.class.where(id: rid).chronological.last end |
#pred ⇒ Object
Returns the previous history entry, or nil if this is the first one.
155 156 157 158 159 160 161 162 163 |
# File 'lib/chrono_model/time_machine/history_model.rb', line 155 def pred return if self.valid_from.nil? if self.class.timeline_associations.empty? self.class.where('id = ? AND upper(validity) = ?', rid, valid_from).first else super(id: rid, before: valid_from, table: self.class.superclass.quoted_table_name) end end |
#record ⇒ Object
:nodoc:
197 198 199 200 |
# File 'lib/chrono_model/time_machine/history_model.rb', line 197 def record #:nodoc: ActiveSupport::Deprecation.warn '.record is deprecated in favour of .current_version' self.current_version end |
#recorded_at ⇒ Object
211 212 213 |
# File 'lib/chrono_model/time_machine/history_model.rb', line 211 def recorded_at ChronoModel::Conversions.string_to_utc_time attributes_before_type_cast['recorded_at'] end |
#rid ⇒ Object
Referenced record ID.
132 133 134 |
# File 'lib/chrono_model/time_machine/history_model.rb', line 132 def rid attributes[self.class.primary_key] end |
#save ⇒ Object
136 137 138 |
# File 'lib/chrono_model/time_machine/history_model.rb', line 136 def save(*) self.class.with_hid_pkey { super } end |
#save! ⇒ Object
140 141 142 |
# File 'lib/chrono_model/time_machine/history_model.rb', line 140 def save!(*) self.class.with_hid_pkey { super } end |
#succ ⇒ Object Also known as: next
Returns the next history entry, or nil if this is the last one.
168 169 170 171 172 173 174 175 176 |
# File 'lib/chrono_model/time_machine/history_model.rb', line 168 def succ return if self.valid_to.nil? if self.class.timeline_associations.empty? self.class.where('id = ? AND lower(validity) = ?', rid, valid_to).first else super(id: rid, after: valid_to, table: self.class.superclass.quoted_table_name) end end |
#update_columns ⇒ Object
144 145 146 |
# File 'lib/chrono_model/time_machine/history_model.rb', line 144 def update_columns(*) self.class.with_hid_pkey { super } end |
#valid_from ⇒ Object
202 203 204 |
# File 'lib/chrono_model/time_machine/history_model.rb', line 202 def valid_from validity.first end |
#valid_to ⇒ Object Also known as: as_of_time
206 207 208 |
# File 'lib/chrono_model/time_machine/history_model.rb', line 206 def valid_to validity.last end |