Class: Version

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
Enumerize
Defined in:
app/models/version.rb

Overview

Informations

License

Ekylibre - Simple agricultural ERP Copyright (C) 2008-2009 Brice Texier, Thibaud Merigon Copyright (C) 2010-2012 Brice Texier Copyright (C) 2012-2019 Brice Texier, David Joulin

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see www.gnu.org/licenses.

Table: versions

created_at   :datetime         not null
creator_id   :integer
creator_name :string
event        :string           not null
id           :integer          not null, primary key
item_changes :text
item_id      :integer
item_object  :text
item_type    :string

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.customizable?Boolean

Adds method for CustomFields

Returns:

  • (Boolean)

110
111
112
# File 'app/models/version.rb', line 110

def self.customizable?
  false
end

.diff(a, b) ⇒ Object


76
77
78
79
80
81
# File 'app/models/version.rb', line 76

def self.diff(a, b)
  # return a.diff(b)
  a.dup
   .delete_if { |k, v| b[k] == v }
   .merge!(b.dup.delete_if { |k, _v| a.key?(k) })
end

Instance Method Details

#changesObject


95
96
97
98
99
# File 'app/models/version.rb', line 95

def changes
  @changes ||= item_changes.collect do |name, value|
    VersionChange.new(self, name, value, item_object[name])
  end
end

#followingObject


87
88
89
# File 'app/models/version.rb', line 87

def following
  @following ||= siblings.after(self.created_at).first
end

#previousObject


91
92
93
# File 'app/models/version.rb', line 91

def previous
  @previous ||= siblings.before(self.created_at).first
end

#siblingsObject


83
84
85
# File 'app/models/version.rb', line 83

def siblings
  item.versions
end

#visible_changesObject


101
102
103
104
105
106
107
# File 'app/models/version.rb', line 101

def visible_changes
  @changes ||= item_changes.collect do |name, value|
    unless value.blank? && item_object[name].blank?
      VersionChange.new(self, name, value, item_object[name])
    end
  end
end