Sha256: 56cd041047958eead2a88820318f132ba6897366eaceafc50c5031e80c274e84

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

module Knitkit
  module Extensions
    module ActiveRecord
      module ActsAsPublishable
        def self.included(base)
          base.extend(ClassMethods)
        end

        module ClassMethods

          def can_be_published
            after_destroy :delete_published_elements

            extend ActsAsPublishable::SingletonMethods
            include ActsAsPublishable::InstanceMethods
          end

        end

        module SingletonMethods
        end

        module InstanceMethods
          def publish(site, comment, version, current_user)
            site.publish_element(comment, self, version, current_user)
          end

          def delete_published_elements
            PublishedElement.delete_all("published_element_record_id = '#{id}' and (published_element_record_type = '#{self.class.to_s}' or published_element_record_type = '#{self.class.superclass.to_s}')")
          end
        end

      end #ActsAsPublishable
    end #ActiveRecord
  end #Extensions
end #Knitkit

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
knitkit-3.2.0 lib/knitkit/extensions/active_record/acts_as_publishable.rb
knitkit-3.0.0 lib/knitkit/extensions/active_record/acts_as_publishable.rb