Module: Cms::Behaviors::VersionRecord

Defined in:
lib/cms/behaviors/versioning.rb

Overview

Represents a record as of a specific version in the versions table.

Instance Method Summary collapse

Instance Method Details

#build_object_from_versionObject

Create an original ‘record’ of the Versioned about as it existed as of this VersionRecord.

Returns:

  • (Object)

    i.e. HtmlBlock



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/cms/behaviors/versioning.rb', line 21

def build_object_from_version()
  obj = versioned_class.new

  (versioned_class.versioned_columns + [:version, :created_at, :created_by_id, :updated_at, :updated_by_id]).each do |a|
    obj.send("#{a}=", self.send(a))
  end
  obj.id = original_record_id

  #obj.lock_version = lock_version

  # Need to do this so associations can be loaded
  obj.instance_variable_set("@persisted", true)
  obj.instance_variable_set("@new_record", false)

  # Callback to allow us to load other data when an older version is loaded
  obj.after_as_of_version if obj.respond_to?(:after_as_of_version)

  # Last but not least, clear the changed attributes
  if changed_attrs = obj.send(:changed_attributes)
    changed_attrs.clear
  end

  obj
end