module ActiveVersioning::Model

Public Instance Methods

commit(params = {}) click to toggle source
# File lib/active_versioning/model/version_proxy.rb, line 87
def commit(params = {})
  raise draft_exception unless version.draft?

  attrs = version_attributes.tap do |attrs|
    attrs.merge!(
      draft:        false,
      event:        ActiveVersioning::Events::COMMIT,
      committed_at: Time.current
    )

    attrs.merge!(params)
  end

  version.update(attrs)

  __getobj__.update(versioned_attributes)
end
live?() click to toggle source
# File lib/active_versioning/model/version_proxy.rb, line 79
def live?
  false
end
reify() click to toggle source
# File lib/active_versioning/model.rb, line 26
def reify
  resource = reload_versionable

  # Necessary to ensure resource and versionable are two distinct objects in memory
  reload_versionable

  resource.assign_attributes(object.slice(*resource.versioned_attribute_names))
  resource
end
save(*) click to toggle source
# File lib/active_versioning/model/version_proxy.rb, line 43
def save(*)
  if valid?
    version.update(version_attributes)
  else
    false
  end
end
save!(*) click to toggle source
# File lib/active_versioning/model/version_proxy.rb, line 51
def save!(*)
  if valid?
    version.update!(version_attributes)
  else
    raise ::ActiveRecord::RecordInvalid.new(__getobj__)
  end
end
to_param() click to toggle source
# File lib/active_versioning/model/version_proxy.rb, line 39
def to_param
  version.versionable.to_param
end
to_s() click to toggle source
# File lib/active_versioning/model.rb, line 19
def to_s
  [
    versionable.to_s,
    committed_at.try(:utc).try(:strftime, '#%Y%m%d%H%M%S')
  ].compact.join(' ')
end
update(attributes) click to toggle source
# File lib/active_versioning/model/version_proxy.rb, line 59
def update(attributes)
  raise draft_exception unless version.draft?

  with_transaction_returning_status do
    assign_attributes(attributes)
    save
  end
end
Also aliased as: update_attributes
update!(attributes) click to toggle source
# File lib/active_versioning/model/version_proxy.rb, line 69
def update!(attributes)
  raise draft_exception unless version.draft?

  with_transaction_returning_status do
    assign_attributes(attributes)
    save!
  end
end
Also aliased as: update_attributes!
update_attributes(attributes)
Alias for: update
update_attributes!(attributes)
Alias for: update!
version?() click to toggle source
# File lib/active_versioning/model/version_proxy.rb, line 83
def version?
  true
end

Private Instance Methods

draft_exception() click to toggle source
# File lib/active_versioning/model/version_proxy.rb, line 107
def draft_exception
  ActiveVersioning::Errors::InvalidVersion.new("Version #{version.id} must be a draft")
end
version_attributes() click to toggle source
# File lib/active_versioning/model/version_proxy.rb, line 111
def version_attributes
  {
    committer: version_author,
    object:    versioned_attributes
  }
end