Sha256: a62f015147315ecb2300e534f73f015dcc7730aff90466c3893ee97320457af0

Contents?: true

Size: 815 Bytes

Versions: 20

Compression:

Stored size: 815 Bytes

Contents

# frozen_string_literal: true

class Serega
  module SeregaValidations
    module Utils
      #
      # Utility to check hash key value is String or Symbol
      #
      class CheckOptIsStringOrSymbol
        # Checks hash key has String or Symbol value
        #
        # @param opts [Hash] Some options Hash
        # @param key [Object] Hash key
        #
        # @raise [Serega::SeregaError] error when provided key exists and value is not String or Symbol
        #
        # @return [void]
        def self.call(opts, key)
          return unless opts.key?(key)

          value = opts[key]
          return if value.is_a?(String) || value.is_a?(Symbol)

          raise SeregaError, "Invalid option #{key.inspect} => #{value.inspect}. Must be a String or a Symbol"
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
serega-0.21.0 lib/serega/validations/utils/check_opt_is_string_or_symbol.rb
serega-0.20.1 lib/serega/validations/utils/check_opt_is_string_or_symbol.rb
serega-0.20.0 lib/serega/validations/utils/check_opt_is_string_or_symbol.rb
serega-0.19.0 lib/serega/validations/utils/check_opt_is_string_or_symbol.rb
serega-0.18.0 lib/serega/validations/utils/check_opt_is_string_or_symbol.rb
serega-0.17.0 lib/serega/validations/utils/check_opt_is_string_or_symbol.rb
serega-0.16.0 lib/serega/validations/utils/check_opt_is_string_or_symbol.rb
serega-0.15.0 lib/serega/validations/utils/check_opt_is_string_or_symbol.rb
serega-0.14.0 lib/serega/validations/utils/check_opt_is_string_or_symbol.rb
serega-0.12.0 lib/serega/validations/utils/check_opt_is_string_or_symbol.rb
serega-0.11.2 lib/serega/validations/utils/check_opt_is_string_or_symbol.rb
serega-0.11.1 lib/serega/validations/utils/check_opt_is_string_or_symbol.rb
serega-0.11.0 lib/serega/validations/utils/check_opt_is_string_or_symbol.rb
serega-0.10.0 lib/serega/validations/utils/check_opt_is_string_or_symbol.rb
serega-0.9.0 lib/serega/validations/utils/check_opt_is_string_or_symbol.rb
serega-0.8.3 lib/serega/validations/utils/check_opt_is_string_or_symbol.rb
serega-0.8.2 lib/serega/validations/utils/check_opt_is_string_or_symbol.rb
serega-0.8.1 lib/serega/validations/utils/check_opt_is_string_or_symbol.rb
serega-0.8.0 lib/serega/validations/utils/check_opt_is_string_or_symbol.rb
serega-0.7.0 lib/serega/validations/utils/check_opt_is_string_or_symbol.rb