Class: SolidusPromotions::PromotionLane

Inherits:
ActiveSupport::CurrentAttributes
  • Object
show all
Defined in:
app/models/solidus_promotions/promotion_lane.rb

Overview

PromotionLane is a thread-safe current attributes class that manages the current promotion lane context.

This class extends ActiveSupport::CurrentAttributes to provide thread-local storage for the current promotion lane. It allows setting and retrieving the current lane, as well as getting all lanes that come before the current one.

Examples:

Setting and retrieving the current lane

PromotionLane.current_lane = :pre
PromotionLane.current_lane # => "pre"

Getting lanes before the current one

PromotionLane.current_lane = :post
PromotionLane.previous_lanes # => ["pre"]

See Also:

  • ActiveSupport::CurrentAttributes

Instance Method Summary collapse

Instance Method Details

#current_lane=(arg) ⇒ Object



22
23
24
25
26
27
28
# File 'app/models/solidus_promotions/promotion_lane.rb', line 22

def current_lane=(arg)
  if arg.present?
    super(arg.to_s)
  else
    super
  end
end

#previous_lanesArray<String>

Retrieves the lanes that occur before the current lane in the promotion flow.

Delegates to ‘before(current_lane)` to compute the preceding lanes.

Special considerations:

  • If ‘current_lane` is `nil`, all lanes are returned.

Returns:

  • (Array<String>)

    the set of lanes preceding the current lane; all lanes if no current lane is set



38
39
40
# File 'app/models/solidus_promotions/promotion_lane.rb', line 38

def previous_lanes
  before(current_lane)
end