Module: Axn::Core::Contract::FieldOptionality
- Included in:
- FieldConfig, ShapeConfig
- Defined in:
- lib/axn/core/contract.rb
Overview
Optionality is shared by FieldConfig and ShapeConfig: a field is optional exactly when its
validators accept nil. Keyed on the validators rather than on the presence of a presence: true
entry, so a field that rejects nil by type alone (allow_empty: true, presence: false) reads as
required here and in the schema.
This is the same NIL-TOLERANCE question schema reflection asks, and the only requiredness signal
here — but schema requiredness ALSO admits a usable default: (schema.rb#optional_for_schema?), so
a field carrying a literal default no presence check would reject (default: 1) is omittable there
while reporting non-optional here. Narrowly that one shape: a Proc default is unknowable at
declaration and reflects as required, and a blank literal default is rejected by the default
presence: true, so both of those agree.
Instance Method Summary collapse
Instance Method Details
#optional? ⇒ Boolean
55 56 57 |
# File 'lib/axn/core/contract.rb', line 55 def optional? Axn::Validation::Base.nil_accepted?(validations) end |