Class: ConvenientService::Utils::Hash::AssertValidKeys Private

Inherits:
Support::Command show all
Defined in:
lib/convenient_service/utils/hash/assert_valid_keys.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Examples:

Common usage.

ConvenientService::Utils::Hash::AssertValidKeys.call({foo: "foo", bar: "bar"}, [:foo, :bar])

Since:

  • 1.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Support::Command

[], call

Constructor Details

#initialize(hash, valid_keys) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

Since:

  • 1.0.0



33
34
35
36
# File 'lib/convenient_service/utils/hash/assert_valid_keys.rb', line 33

def initialize(hash, valid_keys)
  @hash = hash
  @valid_keys = valid_keys.flatten
end

Instance Attribute Details

#hashObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 1.0.0



20
21
22
# File 'lib/convenient_service/utils/hash/assert_valid_keys.rb', line 20

def hash
  @hash
end

#valid_keysObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 1.0.0



26
27
28
# File 'lib/convenient_service/utils/hash/assert_valid_keys.rb', line 26

def valid_keys
  @valid_keys
end

Instance Method Details

#callHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

Since:

  • 1.0.0



45
46
47
48
49
50
51
# File 'lib/convenient_service/utils/hash/assert_valid_keys.rb', line 45

def call
  hash.each_key do |key|
    next if valid_keys.include?(key)

    ::ConvenientService.raise ::ArgumentError.new("Unknown key: #{key.inspect}. Valid keys are: #{valid_keys.map(&:inspect).join(", ")}")
  end
end