Module: SpreeCmCommissioner::OrderChannelBitwise

Extended by:
ActiveSupport::Concern
Defined in:
app/models/concerns/spree_cm_commissioner/order_channel_bitwise.rb

Constant Summary collapse

SPREE_CHANNEL =
'spree'.freeze
GOOGLE_FORM_CHANNEL =
'google_form'.freeze
TELEGRAM_CHANNEL =
'telegram'.freeze
TICKET_TRANSFER_CHANNEL =
'ticket_transfer'.freeze
OFFLINE_SELL_CHANNEL =
'offline_sell'.freeze
ALLOWED_CHANNEL_PREFIXES =
[
  SPREE_CHANNEL, GOOGLE_FORM_CHANNEL, TELEGRAM_CHANNEL, TICKET_TRANSFER_CHANNEL, OFFLINE_SELL_CHANNEL
].freeze
SORTED_CHANNEL_PREFIXES =

Matched longest-first so a future 'spree_x' can never be swallowed by 'spree'.

ALLOWED_CHANNEL_PREFIXES.sort_by { |prefix| -prefix.length }.freeze
CHANNEL_ALERT_BITS =

Bit values are PERSISTED in vendor preferences and are a permanent contract. Never renumber, reorder, or reuse a bit. To retire a channel, leave its bit burned and take the next free power of two.

Deliberately literal, never derived from ALLOWED_CHANNEL_PREFIXES.index — reordering that array would silently remap every vendor's saved setting.

{
  SPREE_CHANNEL => 1,            # 1 << 0
  GOOGLE_FORM_CHANNEL => 2,      # 1 << 1
  TELEGRAM_CHANNEL => 4,         # 1 << 2
  TICKET_TRANSFER_CHANNEL => 8,  # 1 << 3
  OFFLINE_SELL_CHANNEL => 16     # 1 << 4
}.freeze
KNOWN_CHANNEL_ALERT_BITS =

Every bit currently in use, for masking untrusted input down to known channels.

CHANNEL_ALERT_BITS.values.reduce(:|).freeze
DEFAULT_TELEGRAM_ALERT_CHANNELS =

Only online orders alert by default. google_form & ticket_transfer set the state column directly instead of firing the state machine, so they have never sent an alert; this default therefore encodes today's real behaviour rather than changing it.

Instance Method Summary collapse

Instance Method Details

#channel_keyObject

The stored channel may carry a suffix — the importer writes "google_form-<import_order_id>-" — so the prefix, not the whole string, is the channel's identity. Returns nil for an unrecognized channel.



53
54
55
# File 'app/models/concerns/spree_cm_commissioner/order_channel_bitwise.rb', line 53

def channel_key
  SORTED_CHANNEL_PREFIXES.find { |prefix| channel&.start_with?(prefix) }
end

#offline_sell?Boolean

Order was created by an operator through the back-office Sell Ticket console.

Returns:

  • (Boolean)


58
59
60
# File 'app/models/concerns/spree_cm_commissioner/order_channel_bitwise.rb', line 58

def offline_sell?
  channel_key == OFFLINE_SELL_CHANNEL
end