Method: ICFS::Validate.type

Defined in:
lib/icfs/validate.rb

.type(obj, val) ⇒ String, NilClass

check for a type

Parameters:

  • obj (Object)

    object to validate

  • val (Hash)

    options

Options Hash (val):

  • :type (Class, Array)

    The class or module to check

Returns:

  • (String, NilClass)

    error descriptions



172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/icfs/validate.rb', line 172

def self.type(obj, val)
  if val[:type]
    if val[:type].is_a?(Array)
      val[:type].each{|cl| return nil if obj.is_a?(cl) }
      return 'not a listed type'.freeze
    else
      if !obj.is_a?(val[:type])
        return 'not a %s'.freeze % val[:type].name
      end
    end
  end
  return nil
end