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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Support::Command

[], call

Constructor Details

#initialize(hash, valid_keys) ⇒ void

Parameters:



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)

Returns the value of attribute hash.



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

def hash
  @hash
end

#valid_keysObject (readonly)

Returns the value of attribute valid_keys.



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

Returns:



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