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:



28
29
30
31
# File 'lib/convenient_service/utils/hash/assert_valid_keys.rb', line 28

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

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



15
16
17
# File 'lib/convenient_service/utils/hash/assert_valid_keys.rb', line 15

def hash
  @hash
end

#valid_keysObject (readonly)

Returns the value of attribute valid_keys.



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

def valid_keys
  @valid_keys
end

Instance Method Details

#callHash

Returns:



40
41
42
43
44
45
46
# File 'lib/convenient_service/utils/hash/assert_valid_keys.rb', line 40

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