class StrongJSON::Type::Hash

Attributes

type[R]

@dynamic type

Public Class Methods

new(type) click to toggle source
# File lib/strong_json/type.rb, line 346
def initialize(type)
  @type = type
end

Public Instance Methods

==(other) click to toggle source
# File lib/strong_json/type.rb, line 362
def ==(other)
  if other.is_a?(Hash)
    other.type == type
  end
end
coerce(value, path: ErrorPath.root(self)) click to toggle source
# File lib/strong_json/type.rb, line 350
def coerce(value, path: ErrorPath.root(self))
  if value.is_a?(::Hash)
    (_ = {}).tap do |result|
      value.each do |k, v|
        result[k] = type.coerce(v, path: path.dig(key: k, type: type))
      end
    end
  else
    raise TypeError.new(path: path, value: value)
  end
end