Sha256: f418b6c923114821473ebe4187d1a5a85c86fed7dbe7491ce5bbabc0a5c94c57
Contents?: true
Size: 1.01 KB
Versions: 11
Compression:
Stored size: 1.01 KB
Contents
# frozen_string_literal: true require 'media_types/scheme/errors' module MediaTypes class Scheme class OutputTypeGuard class << self def call(*args, **opts, &block) new(*args, **opts).call(&block) end end def initialize(output, options, rules:) self.output = output self.options = options self.expected_type = rules.expected_type end def call return unless expected_type && !(expected_type === output) # rubocop:disable Style/CaseEquality raise_type_error!(type: output.class, backtrace: options.backtrace) end private attr_accessor :output, :options, :expected_type def raise_type_error!(type:, backtrace:) raise OutputTypeMismatch, format( 'Expected a %<expected>s, got a %<actual>s at %<backtrace>s', expected: expected_type, actual: type, backtrace: backtrace.join('->') ) end end end end
Version data entries
11 entries across 11 versions & 1 rubygems