Sha256: c44670f1c230f6b82acd71f948324f21b7313250a195290bbcca5ebcb8a8f110

Contents?: true

Size: 1.48 KB

Versions: 21

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true

# @api private
# @since 0.2.0
class Qonfig::Settings::KeyGuard
  class << self
    # @param key [String, Symbol, Object]
    # @return [void]
    #
    # @raise [Qonfig::ArgumentError]
    # @raise [Qonfig::CoreMethodIntersectionError]
    #
    # @api private
    # @since 0.2.0
    def prevent_incomparabilities!(key)
      new(key).prevent_incomparabilities!
    end
  end

  # @return [String, Symbol, Object]
  #
  # @api private
  # @sicne 0.2.0
  attr_reader :key

  # @param key [String, Symbol, Object]
  #
  # @api private
  # @since 0.2.0
  def initialize(key)
    @key = key
  end

  # @return [void]
  #
  # @raise [Qonfig::ArgumentError]
  # @raise [Qonfig::CoreMethodIntersectionError]
  #
  # @api private
  # @since 0.2.0
  def prevent_incomparabilities!
    prevent_incompatible_key_type!
    prevent_core_method_intersection!
  end

  # @return [void]
  #
  # @raise [Qonfig::ArgumentError]
  #
  # @api private
  # @since 0.2.0
  def prevent_incompatible_key_type!
    raise(
      Qonfig::ArgumentError,
      'Setting key should be a symbol or a string!'
    ) unless key.is_a?(Symbol) || key.is_a?(String)
  end

  # @return [void]
  #
  # @raise [Qonfig::CoreMethodIntersectionError]
  #
  # @api private
  # @since 0.2.0
  def prevent_core_method_intersection!
    raise(
      Qonfig::CoreMethodIntersectionError,
      "<#{key}> key can not be used since this is a private core method"
    ) if Qonfig::Settings::CORE_METHODS.include?(key.to_s)
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
qonfig-0.28.0 lib/qonfig/settings/key_guard.rb
qonfig-0.27.0 lib/qonfig/settings/key_guard.rb
qonfig-0.26.0 lib/qonfig/settings/key_guard.rb
qonfig-0.25.0 lib/qonfig/settings/key_guard.rb
qonfig-0.24.1 lib/qonfig/settings/key_guard.rb
qonfig-0.24.0 lib/qonfig/settings/key_guard.rb
qonfig-0.23.0 lib/qonfig/settings/key_guard.rb
qonfig-0.22.0 lib/qonfig/settings/key_guard.rb
qonfig-0.21.0 lib/qonfig/settings/key_guard.rb
qonfig-0.20.0 lib/qonfig/settings/key_guard.rb
qonfig-0.19.1 lib/qonfig/settings/key_guard.rb
qonfig-0.19.0 lib/qonfig/settings/key_guard.rb
qonfig-0.18.1 lib/qonfig/settings/key_guard.rb
qonfig-0.18.0 lib/qonfig/settings/key_guard.rb
qonfig-0.17.0 lib/qonfig/settings/key_guard.rb
qonfig-0.16.0 lib/qonfig/settings/key_guard.rb
qonfig-0.15.0 lib/qonfig/settings/key_guard.rb
qonfig-0.14.0 lib/qonfig/settings/key_guard.rb
qonfig-0.13.0 lib/qonfig/settings/key_guard.rb
qonfig-0.12.0 lib/qonfig/settings/key_guard.rb