Class: RiceBubble::Attributes::Optional
- Defined in:
- lib/rice_bubble/attributes/optional.rb
Instance Attribute Summary collapse
-
#child ⇒ Object
readonly
Returns the value of attribute child.
Instance Method Summary collapse
- #call(value, path: '') ⇒ Object
- #description ⇒ Object
-
#initialize(child) ⇒ Optional
constructor
A new instance of Optional.
- #valid?(value) ⇒ Boolean
Methods inherited from Base
#fetch, #optional, #valid_types
Constructor Details
#initialize(child) ⇒ Optional
Returns a new instance of Optional.
6 7 8 9 |
# File 'lib/rice_bubble/attributes/optional.rb', line 6 def initialize(child, &) super(&) @child = child end |
Instance Attribute Details
#child ⇒ Object (readonly)
Returns the value of attribute child.
4 5 6 |
# File 'lib/rice_bubble/attributes/optional.rb', line 4 def child @child end |
Instance Method Details
#call(value, path: '') ⇒ Object
15 16 17 |
# File 'lib/rice_bubble/attributes/optional.rb', line 15 def call(value, path: '') value && child.call(value, path:) end |
#description ⇒ Object
19 20 21 |
# File 'lib/rice_bubble/attributes/optional.rb', line 19 def description "#{child.description} (optional)" end |
#valid?(value) ⇒ Boolean
11 12 13 |
# File 'lib/rice_bubble/attributes/optional.rb', line 11 def valid?(value) value.nil? || child.valid?(value) end |