module VestalVersions::Creation::InstanceMethods

Instance methods that determine whether to save a version and actually perform the save.

Private Instance Methods

create_version() click to toggle source

Creates a new version upon updating the parent record.

# File lib/vestal_versions/creation.rb, line 42
def create_version
  versions.create(version_attributes)
  reset_version_changes
  reset_version
end
create_version?() click to toggle source

Returns whether a new version should be created upon updating the parent record.

# File lib/vestal_versions/creation.rb, line 37
def create_version?
  !version_changes.blank?
end
update_version() click to toggle source

Updates the last version's changes by appending the current version changes.

# File lib/vestal_versions/creation.rb, line 56
def update_version
  return create_version unless v = versions.last
  v.changes_will_change!
  v.update_attribute(:changes, v.changes.append_changes(version_changes))
  reset_version_changes
  reset_version
end
update_version?() click to toggle source

Returns whether the last version should be updated upon updating the parent record. This method is overridden in VestalVersions::Control to account for a control block that merges changes onto the previous version.

# File lib/vestal_versions/creation.rb, line 51
def update_version?
  false
end
version_attributes() click to toggle source

Specifies the attributes used during version creation. This is separated into its own method so that it can be overridden by the VestalVersions::Users feature.

# File lib/vestal_versions/creation.rb, line 80
def version_attributes
  {:changes => version_changes, :number => last_version + 1}
end
versioned_columns() click to toggle source

Returns an array of column names that should be included in the changes of created versions. If vestal_versions_options[:only] is specified, only those columns will be versioned. Otherwise, if vestal_versions_options[:except] is specified, all columns will be versioned other than those specified. Without either option, the default is to version all columns. At any rate, the four “automagic” timestamp columns maintained by Rails are never versioned.

# File lib/vestal_versions/creation.rb, line 70
def versioned_columns
  case
    when vestal_versions_options[:only] then self.class.column_names & vestal_versions_options[:only]
    when vestal_versions_options[:except] then self.class.column_names - vestal_versions_options[:except]
    else self.class.column_names
  end - %w(created_at created_on updated_at updated_on)
end