AlchemyCMS/alchemy_cms

View on GitHub
app/models/alchemy/current.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
module Alchemy
  class Current < ActiveSupport::CurrentAttributes
    attribute :preview_page, :page, :language, :site

    def language
      super || Language.default
    end

    def site
      super || Site.first
    end

    def preview_page=(page)
      super

      self.page = page
      self.language = page&.language
      self.site = page&.site
    end

    def preview_page?(page = Current.page)
      return false if preview_page.nil?
      preview_page == page
    end
  end
end