Skip to content

Improve array/hash building syntax. #9

@armstnp

Description

@armstnp

Right now, nested array and hash validations lead to a 'paren cascade' - which, while it may be suitable for a Lisp, looks quite uncomfortable in Ruby.

A more robust instance_eval-based builder may be sufficient to make construction of these validations more compact and more declarative.

This syntax would probably depend on #7.

Possible example of syntax:

hash {
  before { rule(error: :invalid_key) { !_1.key? :bad_key } }

  mandatory(:field_a) { typed(T::Decimal) > gteq(0) & lteq(100) }
  optional(:field_b) { typed(T::String) }

  after { rule(error: :mismatch) { _1[:field_b].nil? || _1[:field_a].to_s == _1[:field_b] } }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions