Skip to content

type coercion of attributes #236

@notEthan

Description

@notEthan

Base#[] could coerce children's types, based on format keyword or other indications of a more natural representation. e.g.:

  • format: date-time coerces to a ruby Time
  • format: uuid coerces to UUIDTools::UUID
    • application will have to install/Gemfile external dependencies
  • type: array + uniqueItems: true coerces to Set?
    • weird one. if the Set contains JSIs (ArrayNode#to_ary), they will never be equal, so never uniq'd (being at different pointers - unless I do end up changing Base#==/#hash to disregard pointer). I could skip adding nodes whose content is already in the Set, but that sounds bad.
    • Set is not appropriate if items is an array (or prefixItems/postfixItems used, later)
      • Set is, in practice, ordered, but not in theory.
      • if I do any uniquifying, indices will not match anyway
    • probably not a worthwhile idea, all around.

more thoughts:

  • Base#[]= must coerce opposite to Base#[]. instance data must stay as json types.
  • memoization or recalculation of coerced values? storing a coerced value from a setter? is coercion roundtrip-safe?
  • lots in common here with ActiveRecord/other ORMs' coercions from database types to ruby

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions