class AttributedObjectHelpers::TypeCheck

Public Class Methods

check(type_info, value) click to toggle source
# File lib/attributed_object_helpers/type_check.rb, line 18
def self.check(type_info, value)
  return value.is_a?(type_info) if type_info.is_a?(Class)

  case type_info
  when :string
    return value.is_a?(String)
  when :boolean
    return value == true || value == false
  when :integer
    return value.is_a?(Integer)
  when :float
    return value.is_a?(Float)
  when :numeric
    return value.is_a?(Numeric)
  when :symbol
    return value.is_a?(Symbol)
  when :array
    return value.is_a?(Array)
  when :hash
    return value.is_a?(Hash)
  else
    if type_info.is_a?(AttributedObject::Type)
      return type_info.strict_check(value)
    end
    raise AttributedObject::ConfigurationError.new("Unknown Type for type checking #{type_info}")
  end
end
check_type_supported!(type_info) click to toggle source
# File lib/attributed_object_helpers/type_check.rb, line 3
def self.check_type_supported!(type_info)
  supported = type_info.is_a?(Class) || [
    :string,
    :boolean,
    :integer,
    :float,
    :numeric,
    :symbol,
    :array,
    :hash
  ].include?(type_info)
  supported = type_info.is_a?(AttributedObject::Type) if !supported
  raise AttributedObject::ConfigurationError.new("Unknown Type for type checking #{type_info}") unless supported
end