Skip to content

Conversation

@dennispatterson
Copy link

A multi-type array with a Boolean allowed type (e.g. 'attribute :multiple_birth, *Fhir::Type[Boolean, Integer]' in Patient) is really supporting instances of Virtus::Attribute::Boolean. The existing coercer allows an attribute to be of this type, but doesn't accept a value of true or false since those are instances of TrueClass and FalseClass, respectively.

Proposed updates:

  • coerce_according_to_types / check_type! - when the allowed type is Virtus::Attribute::Boolean, allow for TrueClass and FalseClass.
  • call - check the type of the coerced value so that a string like "true" can still be coerced into a boolean.
  • virtus_coerce
    • Demodulize the type's name so that it looks for a "to_boolean" method on the coercer.
    • Rescue from an UnsupportedCoercion because coercers can't always coerce to a type just because they have a method to do so. Example: An integer coercer has a to_boolean method but can't coerce an integer such as 2.
    • True and false don't need to be coerced into booleans, so just return those values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant