Sha256: 8b8a3903f2d3b00e7f7cda4fd792cc1cf75df39ddb3a39eb63a66382c4e790bf
Contents?: true
Size: 1 KB
Versions: 4
Compression:
Stored size: 1 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 %<expected>s, got %<actual>s at %<backtrace>s', expected: expected_type, actual: type, backtrace: backtrace.join('->') ) end end end end
Version data entries
4 entries across 4 versions & 1 rubygems