Class: MediaTypes::Scheme::OutputTypeGuard

Inherits:
Object
  • Object
show all
Defined in:
lib/media_types/scheme/output_type_guard.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output, options, rules:) ⇒ OutputTypeGuard

Returns a new instance of OutputTypeGuard.



14
15
16
17
18
# File 'lib/media_types/scheme/output_type_guard.rb', line 14

def initialize(output, options, rules:)
  self.output = output
  self.options = options
  self.expected_type = rules.expected_type
end

Class Method Details

.call(*args, **opts, &block) ⇒ Object



9
10
11
# File 'lib/media_types/scheme/output_type_guard.rb', line 9

def call(*args, **opts, &block)
  new(*args, **opts).call(&block)
end

Instance Method Details

#callObject



20
21
22
23
# File 'lib/media_types/scheme/output_type_guard.rb', line 20

def call
  return unless expected_type && !(expected_type === output) # rubocop:disable Style/CaseEquality
  raise_type_error!(type: output.class, backtrace: options.backtrace)
end