Module: SpreeCmCommissioner::ParticipationTypeBitwise
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/spree_cm_commissioner/participation_type_bitwise.rb
Constant Summary collapse
- BIT_FIELDS =
{ invitation_only: 0b1, public: 0b10, private: 0b100, virtual: 0b1000, free: 0b10000, internal: 0b100000 }.freeze
- ORDERED_BIT_FIELDS =
%i[ invitation_only public private virtual free internal ].freeze
Instance Method Summary collapse
- #participation_type? ⇒ Boolean
- #participation_type_enabled?(bit_value) ⇒ Boolean
- #participation_type_fields ⇒ Object
- #unordered_participation_type_fields ⇒ Object
Instance Method Details
#participation_type? ⇒ Boolean
23 |
# File 'app/models/concerns/spree_cm_commissioner/participation_type_bitwise.rb', line 23 def participation_type? = participation_type != 0 |
#participation_type_enabled?(bit_value) ⇒ Boolean
41 42 43 44 45 |
# File 'app/models/concerns/spree_cm_commissioner/participation_type_bitwise.rb', line 41 def participation_type_enabled?(bit_value) return false if participation_type.nil? participation_type & bit_value != 0 end |
#participation_type_fields ⇒ Object
37 38 39 |
# File 'app/models/concerns/spree_cm_commissioner/participation_type_bitwise.rb', line 37 def participation_type_fields unordered_participation_type_fields.sort_by { |item| ORDERED_BIT_FIELDS.index(item) } end |
#unordered_participation_type_fields ⇒ Object
31 32 33 34 35 |
# File 'app/models/concerns/spree_cm_commissioner/participation_type_bitwise.rb', line 31 def unordered_participation_type_fields BIT_FIELDS.filter_map do |field, bit_value| field if participation_type & bit_value != 0 end end |