class Kafo::DataTypes::WrappedDataType

Public Class Methods

new(*inner_types) click to toggle source
# 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

Public Instance Methods

condition_value(value) click to toggle source
Calls superclass method Kafo::DataType#condition_value
# 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) click to toggle source
Calls superclass method Kafo::DataType#dump_default
# 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?() click to toggle source
# File lib/kafo/data_types/wrapped_data_type.rb, line 18
def multivalued?
  @inner_types.any?(&:multivalued?)
end
to_s() click to toggle source
# File lib/kafo/data_types/wrapped_data_type.rb, line 22
def to_s
  @inner_types.join(' or ')
end
typecast(value) click to toggle source
# 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 = []) click to toggle source
# 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

Private Instance Methods

find_type(value) click to toggle source
# File lib/kafo/data_types/wrapped_data_type.rb, line 43
def find_type(value)
  @inner_types.find { |t| t.valid?(t.typecast(value)) }
end