Module: Stannum::Support::Optional Private
- Included in:
- Attribute, Constraints::Type
- Defined in:
- lib/stannum/support/optional.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Methods for handling optional/required options.
Class Method Summary collapse
Instance Method Summary collapse
-
#optional? ⇒ true, false
private
False if the property accepts nil values, otherwise true.
-
#required? ⇒ true, false
private
True if the property accepts nil values, otherwise false.
Class Method Details
.resolve(optional: nil, required: nil, required_by_default: true, **options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/stannum/support/optional.rb', line 12 def resolve( optional: nil, required: nil, required_by_default: true, ** ) default = validate_option(required_by_default, as: :required_by_default) .merge( required: required?( default: default, optional: validate_option(optional, as: :optional), required: validate_option(required, as: :required) ) ) end |
Instance Method Details
#optional? ⇒ true, false
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns false if the property accepts nil values, otherwise true.
53 54 55 |
# File 'lib/stannum/support/optional.rb', line 53 def optional? ![:required] end |
#required? ⇒ true, false
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns true if the property accepts nil values, otherwise false.
59 60 61 |
# File 'lib/stannum/support/optional.rb', line 59 def required? [:required] end |