Module: Versionable

Extended by:
ActiveSupport::Concern
Included in:
Entity, Issue, Product, SaleOpportunity, Task
Defined in:
app/models/concerns/versionable.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#add_creation_versionObject


15
16
17
# File 'app/models/concerns/versionable.rb', line 15

def add_creation_version
  versions.create!(event: :create)
end

#add_destruction_versionObject


23
24
25
# File 'app/models/concerns/versionable.rb', line 23

def add_destruction_version
  versions.create!(event: :destroy)
end

#add_update_versionObject


19
20
21
# File 'app/models/concerns/versionable.rb', line 19

def add_update_version
  versions.create!(event: :update) if notably_changed?
end

#last_versionObject


34
35
36
# File 'app/models/concerns/versionable.rb', line 34

def last_version
  versions.before(Time.zone.now).first
end

#notably_changed?Boolean

Returns:

  • (Boolean)

27
28
29
30
31
32
# File 'app/models/concerns/versionable.rb', line 27

def notably_changed?
  if version = last_version
    return false if Version.diff(version_object, version.item_object).empty?
  end
  true
end

#version_objectObject


38
39
40
41
42
# File 'app/models/concerns/versionable.rb', line 38

def version_object
  hash = attributes.with_indifferent_access
  hash.delete_if { |k, _v| self.class.versioning_excluded_attributes.include?(k.to_sym) }
  hash
end