lib/vestal_versions.rb in laserlemon-vestal_versions-0.2.4 vs lib/vestal_versions.rb in laserlemon-vestal_versions-0.2.5
- old
+ new
@@ -41,27 +41,24 @@
module InstanceMethods
def build_version
@version = nil
unless changes.blank?
if versions.empty?
- content_columns = self.class.column_names.delete_if{|c| c == self.class.primary_key }.delete_if{|c| c =~ /^(cre|upd)ated_(at|on)$/ }
- content_attributes = attributes.slice(*content_columns)
if new_record?
- versions.build(:changes => content_attributes)
+ versions.build(:changes => attributes)
else
- reverted_attributes = content_attributes.inject({}){|h,(k,v)| h.update(k => (changed.include?(k) ? changes[k].first : v)) }
+ reverted_attributes = attributes.inject({}){|h,(k,v)| h.update(k => (changed.include?(k) ? changes[k].first : v)) }
version_timestamp = (try(:updated_at) || try(:created_at))
versions.build(:changes => reverted_attributes, :created_at => version_timestamp)
end
end
versions.build(:changes => changes) unless new_record?
end
end
def version
@version ||= begin
- last_version = versions.last
- last_version.nil? ? 1 : last_version.number
+ new_record? || (last_version = versions.last).nil? ? 1 : last_version.number
end
end
def revert_to(value)
chain = versions.between(version, value)