This repository was archived by the owner on Jul 5, 2023. It is now read-only.
0.6.0
Release 0.6.0
- Use T.attached_class to reduce the amount of generated code. Thanks to Connor Shea @connorshea
- Add TypedParams to parse action controller params into basic type. Thanks to Donald Dong @donaldong
- Generate T::Enum version of rails enum. Thanks to Alex Ghiculescu @ghiculescu for writing the doc.
- Add sig for
find_or_initialize_by/create_by/create_by!
. Thanks to Matthew Griisser @mgriisser - Add
ActiveRecord::Relation#find_each
. Thanks to Alex Ghiculescu @ghiculescu - Add
ActiveRecord::Relation#empty?
. Thanks to Mikkel Malmberg @mikker
And bug fixes/doc fixes from Todd Siegel @toddsiegel, Daniel Gilchrist @DanielGilchrist
Details:
With TypedEnum now you can have T::Enum
version of Rails Enum
sig { returns(T.nilable(Wizard::House)) }
def typed_house; end
sig { params(value: T.nilable(Wizard::House)).void }
def typed_house=(value); end
See: https://github.com/chanzuckerberg/sorbet-rails#enums
TypedParams is a generalized version of fetch_typed & require_typed, that allows parsing nested params structure
class MyCoolController < ApplicationController
class MyActionParams < T::Struct
const :id, T.nilable(Integer)
const :show, T.nilable(T::Boolean)
const :wands, T::Array[Integer]
end
sig { void }
def my_action
typed_params = TypedParams[MyActionParams].new.extract!(params)
# T.reveal_type(typed_params) => MyActionParams
# T.reveal_type(typed_params.show) => T.nilable(T::Boolean)
end
end
See: https://github.com/chanzuckerberg/sorbet-rails#controllers