Module: Logidze::Model::ClassMethods
- Defined in:
- lib/logidze/model.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#at(time: nil, version: nil) ⇒ Object
Return records reverted to specified time.
-
#create_logidze_snapshot(timestamp: nil, only: nil, except: nil) ⇒ Object
Initialize log_data with the current state if it’s null.
-
#diff_from(time: nil, version: nil) ⇒ Object
Return changes made to records since specified time.
-
#has_logidze? ⇒ Boolean
rubocop: disable Naming/PredicateName.
-
#reset_log_data ⇒ Object
Nullify log_data column for a association.
-
#without_logging(&block) ⇒ Object
Alias for Logidze.without_logging.
Instance Method Details
#at(time: nil, version: nil) ⇒ Object
Return records reverted to specified time
20 21 22 |
# File 'lib/logidze/model.rb', line 20 def at(time: nil, version: nil) initial_scope.all.to_a.filter_map { |record| record.at(time: time, version: version) } end |
#create_logidze_snapshot(timestamp: nil, only: nil, except: nil) ⇒ Object
Initialize log_data with the current state if it’s null
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/logidze/model.rb', line 46 def create_logidze_snapshot(timestamp: nil, only: nil, except: nil) without_logging do where(log_data: nil).update_all( " log_data = logidze_snapshot(\n to_jsonb(\#{quoted_table_name}),\n \#{snapshot_query_args(timestamp: timestamp, only: only, except: except)}\n )\n SQL\n )\n end\nend\n".squish |
#diff_from(time: nil, version: nil) ⇒ Object
Return changes made to records since specified time
25 26 27 |
# File 'lib/logidze/model.rb', line 25 def diff_from(time: nil, version: nil) initial_scope.all.map { |record| record.diff_from(time: time, version: version) } end |
#has_logidze? ⇒ Boolean
rubocop: disable Naming/PredicateName
35 36 37 |
# File 'lib/logidze/model.rb', line 35 def has_logidze? true end |
#reset_log_data ⇒ Object
Nullify log_data column for a association
41 42 43 |
# File 'lib/logidze/model.rb', line 41 def reset_log_data without_logging { update_all(log_data: nil) } end |
#without_logging(&block) ⇒ Object
Alias for Logidze.without_logging
30 31 32 |
# File 'lib/logidze/model.rb', line 30 def without_logging(&block) Logidze.without_logging(&block) end |