Sha256: 6491d5a1251039b71a2d1a065ee9036e82e2972df2e626be4d45da459b98f7b6

Contents?: true

Size: 713 Bytes

Versions: 3

Compression:

Stored size: 713 Bytes

Contents

# frozen_string_literal: true

module BitmaskEnum
  NIL_HANDLING_OPTIONS = [:include].freeze

  # Handles the bitmask enum's user-provided options
  # @api private
  class Options
    attr_reader :flag_prefix, :flag_suffix, :nil_handling, :validate

    def initialize(options)
      @nil_handling = options[:nil_handling].to_sym
      unless NIL_HANDLING_OPTIONS.include?(@nil_handling)
        raise BitmaskEnumInvalidError, "#{@nil_handling} is not a valid nil handling option"
      end

      @flag_prefix = options[:flag_prefix].nil? ? '' : "#{options[:flag_prefix]}_"
      @flag_suffix = options[:flag_suffix].nil? ? '' : "_#{options[:flag_suffix]}"
      @validate = options[:validate]
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bitmask_enum-1.1.1 lib/bitmask_enum/options.rb
bitmask_enum-1.1.0 lib/bitmask_enum/options.rb
bitmask_enum-1.0.0 lib/bitmask_enum/options.rb