Sha256: 88d352286987632213760b3b2a9783abf382340fe64c021a2e33ce1608afc8c7

Contents?: true

Size: 1.15 KB

Versions: 28

Compression:

Stored size: 1.15 KB

Contents

module Workarea
  module CurrentSegments
    extend ActiveSupport::Concern
    include CurrentTracking

    included do
      delegate :override_segments, to: :current_visit
      helper_method :current_segments, :override_segments

      after_action :mark_segmented_content
    end

    def self.segmented_content?
      !!Thread.current[:segmented_content]
    end

    def self.has_segmented_content!
      Thread.current[:segmented_content] = true
    end

    def self.reset_segmented_content
      Thread.current[:segmented_content] = nil
    end

    def override_segments=(segments)
      if segments.blank?
        session.delete(:segment_ids)
        return
      end

      session[:segment_ids] = segments.map(&:id)
      current_visit.override_segments = segments
    end

    def current_segments
      Segment.current
    end

    def apply_segments
      Segment.with_current(current_visit&.applied_segments) { yield }
    end

    def mark_segmented_content
      if CurrentSegments.segmented_content?
        response.set_header('X-Workarea-Segmented-Content', 'true')
      end

    ensure
      CurrentSegments.reset_segmented_content
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

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