Class: Kafo::DataTypes::Optional
- Inherits:
-
Kafo::DataType
- Object
- Kafo::DataType
- Kafo::DataTypes::Optional
- Extended by:
- Forwardable
- Defined in:
- lib/kafo/data_types/optional.rb
Instance Attribute Summary collapse
-
#inner_type ⇒ Object
readonly
Returns the value of attribute inner_type.
-
#inner_value ⇒ Object
readonly
Returns the value of attribute inner_value.
Instance Method Summary collapse
-
#initialize(inner_type_or_value) ⇒ Optional
constructor
A new instance of Optional.
- #to_s ⇒ Object
- #valid?(input, errors = []) ⇒ Boolean
Methods inherited from Kafo::DataType
#condition_value, #dump_default, #multivalued?, new_from_string, parse_hash, register_type, split_arguments, #typecast, types, unregister_type
Constructor Details
#initialize(inner_type_or_value) ⇒ Optional
Returns a new instance of Optional.
8 9 10 11 12 13 14 |
# File 'lib/kafo/data_types/optional.rb', line 8 def initialize(inner_type_or_value) begin @inner_type = DataType.new_from_string(inner_type_or_value) rescue ConfigurationException @inner_value = inner_type_or_value end end |
Instance Attribute Details
#inner_type ⇒ Object (readonly)
Returns the value of attribute inner_type.
6 7 8 |
# File 'lib/kafo/data_types/optional.rb', line 6 def inner_type @inner_type end |
#inner_value ⇒ Object (readonly)
Returns the value of attribute inner_value.
6 7 8 |
# File 'lib/kafo/data_types/optional.rb', line 6 def inner_value @inner_value end |
Instance Method Details
#to_s ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/kafo/data_types/optional.rb', line 16 def to_s if @inner_type "#{@inner_type} or undef" else "#{@inner_value.inspect} or undef" end end |
#valid?(input, errors = []) ⇒ Boolean
24 25 26 27 28 29 |
# File 'lib/kafo/data_types/optional.rb', line 24 def valid?(input, errors = []) return true if input.nil? return true if @inner_type && @inner_type.valid?(input, errors) return true if @inner_value && @inner_value == input return false end |