Class: Kafo::DataTypes::NotUndef

Inherits:
Kafo::DataType show all
Extended by:
Forwardable
Defined in:
lib/kafo/data_types/not_undef.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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) ⇒ NotUndef

Returns a new instance of NotUndef.



10
11
12
13
14
15
16
# File 'lib/kafo/data_types/not_undef.rb', line 10

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_typeObject (readonly)

Returns the value of attribute inner_type.



8
9
10
# File 'lib/kafo/data_types/not_undef.rb', line 8

def inner_type
  @inner_type
end

#inner_valueObject (readonly)

Returns the value of attribute inner_value.



8
9
10
# File 'lib/kafo/data_types/not_undef.rb', line 8

def inner_value
  @inner_value
end

Instance Method Details

#to_sObject



18
19
20
21
22
23
24
# File 'lib/kafo/data_types/not_undef.rb', line 18

def to_s
  if @inner_type
    "#{@inner_type} but not undef"
  else
    "#{@inner_value.inspect} but not undef"
  end
end

#valid?(input, errors = []) ⇒ Boolean

Returns:



26
27
28
29
30
31
# File 'lib/kafo/data_types/not_undef.rb', line 26

def valid?(input, errors = [])
  return false if input.nil?
  return true if @inner_type && @inner_type.valid?(input, errors)
  return true if @inner_value && @inner_value == input
  return false
end