Class: ConvenientService::Utils::Hash::AssertValidKeys
- Inherits:
-
Support::Command
- Object
- Support::Command
- ConvenientService::Utils::Hash::AssertValidKeys
- Defined in:
- lib/convenient_service/utils/hash/assert_valid_keys.rb
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
-
#valid_keys ⇒ Object
readonly
Returns the value of attribute valid_keys.
Instance Method Summary collapse
- #call ⇒ Hash
- #initialize(hash, valid_keys) ⇒ void constructor
Methods inherited from Support::Command
Constructor Details
#initialize(hash, valid_keys) ⇒ void
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
#hash ⇒ Object (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_keys ⇒ Object (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
#call ⇒ Hash
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 |