Sha256: f5478d720beff7da7cd1445f43637844431c7dd0261b6e260935ace8f3b98092

Contents?: true

Size: 1013 Bytes

Versions: 72

Compression:

Stored size: 1013 Bytes

Contents

module Pageflow
  # RevisionComponent represents a model that is attached to the revision
  # mechanism of Pageflow.
  #
  # In order to be used as a ComponentModel a model is required to
  # have an integer field `perma_id` and a belongs_to field `revision`.
  module RevisionComponent
    extend ActiveSupport::Concern

    included do
      belongs_to :revision, class_name: 'Pageflow::Revision'
      before_save :ensure_perma_id
    end

    def copy_to(revision)
      record = dup
      record.revision = revision
      record.save!
    end

    def ensure_perma_id
      self.perma_id ||= (self.class.maximum(:perma_id) || 0) + 1
    end

    module ClassMethods
      def all_for_revision(revision)
        where(revision_id: revision.id)
      end

      def from_perma_ids(revision, perma_ids)
        return [] if revision.blank? || perma_ids.blank?

        perma_ids.map do |perma_id|
          find_by_revision_id_and_perma_id(revision.id, perma_id)
        end.compact
      end
    end
  end
end

Version data entries

72 entries across 72 versions & 1 rubygems

Version Path
pageflow-14.5.2 lib/pageflow/revision_component.rb
pageflow-14.5.1 lib/pageflow/revision_component.rb
pageflow-14.5.0 lib/pageflow/revision_component.rb
pageflow-15.0.0.beta4 lib/pageflow/revision_component.rb
pageflow-15.0.0.beta3 lib/pageflow/revision_component.rb
pageflow-14.4.0 lib/pageflow/revision_component.rb
pageflow-15.0.0.beta2 lib/pageflow/revision_component.rb
pageflow-15.0.0.beta1 lib/pageflow/revision_component.rb
pageflow-14.3.0 lib/pageflow/revision_component.rb
pageflow-14.2.1 lib/pageflow/revision_component.rb
pageflow-14.2.0 lib/pageflow/revision_component.rb
pageflow-14.1.1 lib/pageflow/revision_component.rb
pageflow-14.1.0 lib/pageflow/revision_component.rb
pageflow-14.0.0 lib/pageflow/revision_component.rb
pageflow-14.0.0.rc2 lib/pageflow/revision_component.rb
pageflow-14.0.0.rc1 lib/pageflow/revision_component.rb
pageflow-14.0.0.beta3 lib/pageflow/revision_component.rb
pageflow-14.0.0.beta2 lib/pageflow/revision_component.rb
pageflow-14.0.0.beta1 lib/pageflow/revision_component.rb
pageflow-13.6.0 lib/pageflow/revision_component.rb