Sha256: d7d409a7c433f2e07e77788d5097ce0c0c8cdadc12a0a3d46d98e9e2d1b89451

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

module ControlledVersioning
  class Version < ActiveRecord::Base
    belongs_to :versionable, polymorphic: true
    belongs_to :user
    has_many :version_attributes, as: :version
    has_many :version_children, as: :version

    scope :pending, -> { where(pending: true) }
    scope :accepted, -> { where(accepted: true) }
    scope :declined, -> { where(declined: true) }

    def accept
      if pending?
        Revision::Publisher.new(self).accept_revision unless initial?
        update_attributes(pending: false, accepted: true)
        versionable.try(:when_accepting_anything)
        versionable.try(:when_accepting_an_initial_version) if initial?
        versionable.try(:when_accepting_a_revision) unless initial?
      end
    end

    def decline
      if pending?
        update_attributes(pending: false, declined: true)
        versionable.try(:when_declining_anything)
        versionable.try(:when_declining_an_initial_version) if initial?
        versionable.try(:when_declining_a_revision) unless initial?
      end
    end

    def revisions
      ChangeTracker.new(self)
    end

    def is_a_child?
      false
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
controlled_versioning-0.10.0 app/models/controlled_versioning/version.rb