class FieldMapper::Types::List

Constants

ALLOWED_TYPES

Attributes

type[R]

Public Class Methods

[](type) click to toggle source
# File lib/field_mapper/types/list.rb, line 21
def [](type)
  List.new(type)
end
new(type, values=[]) click to toggle source
# File lib/field_mapper/types/list.rb, line 27
def initialize(type, values=[])
  raise InvalidListType.new("#{type} is not a supported list type") unless valid_type?(type)
  @type = type
end

Public Instance Methods

name() click to toggle source
# File lib/field_mapper/types/list.rb, line 32
def name
  self.class.name
end
plat_list?() click to toggle source
# File lib/field_mapper/types/list.rb, line 36
def plat_list?
  type.ancestors.include?(FieldMapper::Standard::Plat)
end
valid?(list) click to toggle source
# File lib/field_mapper/types/list.rb, line 40
def valid?(list)
  return true if list.empty?
  types = list.map{ |v| v.class }.uniq
  return false if types.length > 1
  types.first.ancestors.include? type
end

Private Instance Methods

valid_type?(type) click to toggle source
# File lib/field_mapper/types/list.rb, line 49
def valid_type?(type)
  return false if type.class != Class
  !(type.ancestors & ALLOWED_TYPES).empty?
end