Class: Kafo::DataTypes::WrappedDataType

Inherits:
Kafo::DataType show all
Defined in:
lib/kafo/data_types/wrapped_data_type.rb

Instance Method Summary collapse

Methods inherited from Kafo::DataType

new_from_string, parse_hash, register_type, split_arguments, types, unregister_type

Constructor Details

#initialize(*inner_types) ⇒ WrappedDataType

Returns a new instance of WrappedDataType.



4
5
6
# File 'lib/kafo/data_types/wrapped_data_type.rb', line 4

def initialize(*inner_types)
  @inner_types = inner_types.map { |t| DataType.new_from_string(t) }
end

Instance Method Details

#condition_value(value) ⇒ Object



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

def condition_value(value)
  type = find_type(value)
  type ? type.condition_value(value) : super(value)
end

#dump_default(value) ⇒ Object



13
14
15
16
# File 'lib/kafo/data_types/wrapped_data_type.rb', line 13

def dump_default(value)
  type = find_type(value)
  type ? type.dump_default(value) : super(value)
end

#multivalued?Boolean

Returns:



18
19
20
# File 'lib/kafo/data_types/wrapped_data_type.rb', line 18

def multivalued?
  @inner_types.any?(&:multivalued?)
end

#to_sObject



22
23
24
# File 'lib/kafo/data_types/wrapped_data_type.rb', line 22

def to_s
  @inner_types.join(' or ')
end

#typecast(value) ⇒ Object



26
27
28
29
# File 'lib/kafo/data_types/wrapped_data_type.rb', line 26

def typecast(value)
  type = find_type(value)
  type ? type.typecast(value) : value
end

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

Returns:



31
32
33
34
35
36
37
38
39
# File 'lib/kafo/data_types/wrapped_data_type.rb', line 31

def valid?(value, errors = [])
  type = find_type(value)
  if type
    type.valid?(value, errors)
  else
    errors << "#{value} is not one of #{self}"
    false
  end
end