Sha256: 16ca510bfdba9a8d358c3d03eecd573486e6ae28eb1dec380f757c519bb96008

Contents?: true

Size: 1.22 KB

Versions: 3

Compression:

Stored size: 1.22 KB

Contents

module ContentState
  class JustPublished < Published
    include Reloadable
    include Singleton

    # We need to save the state as 'Published', but we need after_save
    # to be handled by JustPublished. So, JustPublished tells Rails that
    # it's *actually* Published and all shall be well.
    def memento
      'ContentState::Published'
    end

    def just_published?
      true
    end

    def published?(content)
      true
    end

    def enter_hook(content)
      super
      content[:published] = true
      content[:published_at] ||= Time.now
    end

    def set_published_at(content, new_time)
      content[:published_at] = new_time
      return if content[:published_at].nil?
      if content.published_at > Time.now
        content.state = PublicationPending.instance
      end
    end

    def after_save(content)
      content.state = Published.instance
    end

    def send_notifications(content, controller)
      content.interested_users.each do |user|
        content.send_notification_to_user(controller, user)
      end
    end

    def send_pings(content)
      content.really_send_pings
    end

    def withdraw(content)
      content[:published_at] = nil
      content.state = Factory.new(:draft)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
typo-4.0.2 app/models/content_state/just_published.rb
typo-4.0.1 app/models/content_state/just_published.rb
typo-4.0.3 app/models/content_state/just_published.rb