Class: Hist::Version

Inherits:
ApplicationRecord show all
Defined in:
app/models/hist/version.rb

Class Method Summary collapse

Methods inherited from ApplicationRecord

decode, encode, fix_save_associations, get, include_keys, only_hash_diffs, raw_get, #reify, remove_key, to_json, to_yaml, #without_persisting

Class Method Details

.put(obj:, user: nil, extra: nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/models/hist/version.rb', line 6

def self.put(obj:, user: nil, extra: nil)
  # Trim old versions
  # TODO: make this more efficient
  if obj.class.base_class.hist_config.max_versions >= 0
    versions = self.raw_get(obj: obj)
    if versions.size >= obj.class.base_class.hist_config.max_versions
      versions.last.destroy!
    end
  end

  super
end