class AttributedObject::Types::HashOf

Public Class Methods

new(key_type_info, value_type_info) click to toggle source
# File lib/attributed_object/types/hash_of.rb, line 4
def initialize(key_type_info, value_type_info)
  @key_type_info = key_type_info
  @value_type_info = value_type_info
end

Public Instance Methods

coerce(hash) click to toggle source
# File lib/attributed_object/types/hash_of.rb, line 16
def coerce(hash)
  raise AttributedObject::UncoercibleValueError.new("Trying to coerce into Hash but value is not an hash") if !hash.is_a?(Hash)
  hash.map { |k,v| [AttributedObjectHelpers::TypeCoerce.coerce(@key_type_info, k), AttributedObjectHelpers::TypeCoerce.coerce(@value_type_info, v)] }
end
strict_check(hash) click to toggle source
# File lib/attributed_object/types/hash_of.rb, line 9
def strict_check(hash)
  return false if !hash.is_a?(Hash)
  hash.all? do |k,v|
    AttributedObjectHelpers::TypeCheck.check(@key_type_info, k) && AttributedObjectHelpers::TypeCheck.check(@value_type_info, v)
  end
end