Module: SpreeCmCommissioner::VendorPreference
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/spree_cm_commissioner/vendor_preference.rb
Constant Summary collapse
- TELEGRAM_CHAT_TYPE =
%i[channel group].freeze
Instance Method Summary collapse
-
#alerts_telegram_for_channel?(channel_key) ⇒ Boolean
Should this vendor's Telegram group be alerted for an order on this channel? An unmapped channel alerts — a stray message is a better failure than silence.
-
#telegram_alert_channels_mask ⇒ Object
Spree's getter is
preferences.fetch(name) { default }, which falls back only when the key is ABSENT.
Instance Method Details
#alerts_telegram_for_channel?(channel_key) ⇒ Boolean
Should this vendor's Telegram group be alerted for an order on this channel? An unmapped channel alerts — a stray message is a better failure than silence.
16 17 18 19 20 21 |
# File 'app/models/concerns/spree_cm_commissioner/vendor_preference.rb', line 16 def alerts_telegram_for_channel?(channel_key) bit = SpreeCmCommissioner::OrderChannelBitwise::CHANNEL_ALERT_BITS[channel_key] return true if bit.nil? telegram_alert_channels_mask.anybits?(bit) end |
#telegram_alert_channels_mask ⇒ Object
Spree's getter is preferences.fetch(name) { default }, which falls back only when the
key is ABSENT. A key present with a nil value returns nil, and nil.to_i == 0 would mute
EVERY channel silently. Fall back to the default instead; a deliberate 0 survives
because 0 is truthy in Ruby.
27 28 29 30 |
# File 'app/models/concerns/spree_cm_commissioner/vendor_preference.rb', line 27 def telegram_alert_channels_mask (preferred_telegram_alert_channels || SpreeCmCommissioner::OrderChannelBitwise::DEFAULT_TELEGRAM_ALERT_CHANNELS).to_i end |