Module: SorbetRails::CustomParamsMethods

Extended by:
T::Helpers, T::Sig
Includes:
Kernel
Defined in:
lib/sorbet-rails/rails_mixins/custom_params_methods.rb

Instance Method Summary collapse

Instance Method Details

#fetch_typed(key, ta, *args) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/sorbet-rails/rails_mixins/custom_params_methods.rb', line 37

def fetch_typed(key, ta, *args)
  val = fetch(key, *args)
  ta.assert(val)
rescue TypeError
  raise ActionController::BadRequest.new(
    "Expected parameter #{key} to be an instance of type T.nilable(#{ta.get_type}),
    got `#{val}`".squish!
  )
end

#require_typed(key, ta) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/sorbet-rails/rails_mixins/custom_params_methods.rb', line 18

def require_typed(key, ta)
  val = require(key)
  ta.assert(val)
rescue TypeError
  raise ActionController::BadRequest.new(
    "Expected parameter #{key} to be an instance of type #{ta.get_type}, got `#{val}`"
  )
end