Sha256: be2a1737bdc59e0d43a26cd8965d805c946245e9015681cbb0a8f15f08a80011

Contents?: true

Size: 1.27 KB

Versions: 28

Compression:

Stored size: 1.27 KB

Contents

module Workarea
  module CurrentRelease
    extend ActiveSupport::Concern

    included do
      helper_method :current_release, :current_release_session
      around_action :set_release
      before_action :mark_release_session
    end

    private

    def set_release
      if current_release_id.blank? || !current_user.try(:admin?)
        Release.current = nil
        yield
      else
        Release.with_current(current_release_id) do
          yield
        end
      end
    end

    def mark_release_session
      return unless current_user.try(:admin?)

      if working_with_releases? || current_release.blank?
        current_release_session.reset!
      elsif request.get? && !request.xhr?
        current_release_session.save_page_view
      end
    end

    def working_with_releases?
      request.url =~ /release/ || request.referer =~ /release/
    end

    def current_release_id
      session[:release_id]
    end

    def current_release
      Release.current
    end

    def current_release=(release)
      current_release_session.save_release_change if release.present?
      session[:release_id] = release.try(:id)
      Release.current = release
    end

    def current_release_session
      @current_release_session ||= ReleaseSession.new(session)
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
workarea-core-3.5.27 app/controllers/workarea/current_release.rb
workarea-core-3.5.26 app/controllers/workarea/current_release.rb
workarea-core-3.5.25 app/controllers/workarea/current_release.rb
workarea-core-3.5.23 app/controllers/workarea/current_release.rb
workarea-core-3.5.22 app/controllers/workarea/current_release.rb
workarea-core-3.5.21 app/controllers/workarea/current_release.rb
workarea-core-3.5.20 app/controllers/workarea/current_release.rb
workarea-core-3.5.19 app/controllers/workarea/current_release.rb
workarea-core-3.5.18 app/controllers/workarea/current_release.rb
workarea-core-3.5.17 app/controllers/workarea/current_release.rb
workarea-core-3.5.16 app/controllers/workarea/current_release.rb
workarea-core-3.5.15 app/controllers/workarea/current_release.rb
workarea-core-3.5.14 app/controllers/workarea/current_release.rb
workarea-core-3.5.13 app/controllers/workarea/current_release.rb
workarea-core-3.5.12 app/controllers/workarea/current_release.rb
workarea-core-3.5.11 app/controllers/workarea/current_release.rb
workarea-core-3.5.10 app/controllers/workarea/current_release.rb
workarea-core-3.5.9 app/controllers/workarea/current_release.rb
workarea-core-3.5.8 app/controllers/workarea/current_release.rb
workarea-core-3.5.7 app/controllers/workarea/current_release.rb