Sha256: 60d5d8e91273d5ef4336cb6369a62c0555c132772b8d48bb31361316f9cd3657

Contents?: true

Size: 1.1 KB

Versions: 34

Compression:

Stored size: 1.1 KB

Contents

module Workarea
  class ReleaseSession
    def initialize(cookies)
      @cookies = cookies
    end

    def remind?
      expired_by_time? || expired_by_page_views?
    end

    def expired_by_time?
      @cookies.permanent[:release_changed_at].present? &&
        Time.zone.parse(@cookies.permanent[:release_changed_at]) < timeout
    end

    def timeout
      Workarea.config.release_session_timeout.ago
    end

    def expired_by_page_views?
      @cookies.permanent[:release_page_views].present? &&
        @cookies.permanent[:release_page_views].to_i > max_page_views
    end

    def max_page_views
      Workarea.config.release_session_max_page_views
    end

    def save_page_view
      incremented = @cookies.permanent[:release_page_views].to_i + 1
      @cookies.permanent[:release_page_views] = incremented
    end

    def save_release_change
      reset!
      @cookies.permanent[:release_changed_at] = Time.current.to_s
    end
    alias_method :touch, :save_release_change

    def reset!
      @cookies.permanent[:release_page_views] = nil
      @cookies.permanent[:release_changed_at] = nil
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
workarea-core-3.4.45 app/models/workarea/release_session.rb
workarea-core-3.4.44 app/models/workarea/release_session.rb
workarea-core-3.4.43 app/models/workarea/release_session.rb
workarea-core-3.4.42 app/models/workarea/release_session.rb
workarea-core-3.4.41 app/models/workarea/release_session.rb
workarea-core-3.4.40 app/models/workarea/release_session.rb
workarea-core-3.4.39 app/models/workarea/release_session.rb
workarea-core-3.4.38 app/models/workarea/release_session.rb
workarea-core-3.4.37 app/models/workarea/release_session.rb
workarea-core-3.4.36 app/models/workarea/release_session.rb
workarea-core-3.4.35 app/models/workarea/release_session.rb
workarea-core-3.4.34 app/models/workarea/release_session.rb
workarea-core-3.4.33 app/models/workarea/release_session.rb
workarea-core-3.4.32 app/models/workarea/release_session.rb
workarea-core-3.4.31 app/models/workarea/release_session.rb
workarea-core-3.4.30 app/models/workarea/release_session.rb
workarea-core-3.4.29 app/models/workarea/release_session.rb
workarea-core-3.4.28 app/models/workarea/release_session.rb
workarea-core-3.4.27 app/models/workarea/release_session.rb
workarea-core-3.4.26 app/models/workarea/release_session.rb