New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rework resource types #39
Conversation
Open questions are:
|
135c827
to
6680bd2
Compare
* Drop `:allow_nil` and `:allow_blank` `:allow_nil` should be replaced by validations and `:allow_blank` broke much code with less to none use * All type handle nil, empty and blank strings Primitive types cast to false, 0 or 0.0 while other types cast to nil (e.g. DateTime, etc) Type casting is still strict, casting "123a" to integer will raise an error and not return 123 like `#to_i`. List and dict types support more type cohesion methods: `#serializable_hash`, `#to_hash`, `#to_h` on dict and `#to_ary`, `#to_a` on list.
I prefer interpret blank string as Converting everything into arrays is probably the better approach: it simplifies to-array conversations. With non-verified array elements I do not see much advantage on enforcing that we get an array itself. |
* Boolean type: Cast blank strings to nil * List type: Cast non-arrayish object to an array using `Array(value)`
One other question appeared: Acfs uses a whitelist of values that are true when casting boolean. This is somewhat contradictory to how Ruby interprets bool values (everything is true, except falsy things) and how ActiveRecord or ActiveModel do it, using a list of falsy values ( Do we want to change that too? |
I'd actually go for ActiveRecord-like behavior. |
Would go for release when CI passes unless someone objects. |
Drop
allow_nil
andallow_blank
allow_nil
should be replaced by validations andallow_blank
brokemuch code with less to none use.
All type handle
nil
, empty and blank stringsPrimitive types cast to false, 0 or 0.0 while other types cast to nil (e.g. DateTime, etc)
Type casting is still strict, casting "123a" to integer will raise an
error and not return 123 like
#to_i
. List and dict types support moretype cohesion methods:
#serializable_hash
,#to_hash
,#to_h
on dictand
#to_ary
,#to_a
on list./cc @mswart @cwillems