Sha256: bddfb4db6555e6fcef602aa325bbc9b63b9386335486da848ce55da8c6fdeca0

Contents?: true

Size: 671 Bytes

Versions: 26

Compression:

Stored size: 671 Bytes

Contents

# typed: ignore
require 'sorbet-coerce'

if !$PROGRAM_NAME.include?('sorbet')
  module TypedParams
    # A sorbet-coerce wrapper for coercing typed controller parameters
    define_singleton_method(:[]) do |type|
      Class.new do
        define_method(:extract!) do |params, raise_coercion_error: nil|
          begin
            TypeCoerce[type].new.from(
              params.permit!.to_h,
              raise_coercion_error: raise_coercion_error
            )
          rescue TypeCoerce::CoercionError, TypeCoerce::ShapeError, TypeError, ArgumentError => e
            raise ActionController::BadRequest.new(e)
          end
        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
sorbet-rails-0.7.34 lib/sorbet-rails/typed_params.rb
sorbet-rails-0.7.33 lib/sorbet-rails/typed_params.rb
sorbet-rails-0.7.32 lib/sorbet-rails/typed_params.rb
sorbet-rails-0.7.31 lib/sorbet-rails/typed_params.rb
sorbet-rails-0.7.27 lib/sorbet-rails/typed_params.rb
sorbet-rails-0.7.26 lib/sorbet-rails/typed_params.rb
sorbet-rails-0.7.25 lib/sorbet-rails/typed_params.rb
sorbet-rails-0.7.24 lib/sorbet-rails/typed_params.rb
sorbet-rails-0.7.23 lib/sorbet-rails/typed_params.rb
sorbet-rails-0.7.22 lib/sorbet-rails/typed_params.rb
sorbet-rails-0.7.20 lib/sorbet-rails/typed_params.rb
sorbet-rails-0.7.19 lib/sorbet-rails/typed_params.rb
sorbet-rails-0.7.18 lib/sorbet-rails/typed_params.rb
sorbet-rails-0.7.5 lib/sorbet-rails/typed_params.rb
sorbet-rails-0.7.4 lib/sorbet-rails/typed_params.rb
sorbet-rails-0.7.3 lib/sorbet-rails/typed_params.rb
sorbet-rails-0.7.2 lib/sorbet-rails/typed_params.rb
sorbet-rails-0.7.1 lib/sorbet-rails/typed_params.rb
sorbet-rails-0.7.0 lib/sorbet-rails/typed_params.rb
sorbet-rails-0.6.5.1 lib/sorbet-rails/typed_params.rb