module Type
Type
is a library for type-casting and type-validation
The built-in collection types are defined here.
The built-in scalar types are defined here.
Constants
- VERSION
The
Type
gem is semantically versioned.
Public Class Methods
collection(name = nil, &block)
click to toggle source
see Definition::Collection#generate
# File lib/type/definition/collection.rb, line 8 def collection(name = nil, &block) Definition::Collection.generate(name, &block) end
find(query)
click to toggle source
@overload find(query)
@param query [Type::Definition]
@overload find(query)
@param query [String, Symbol] Find a named Type::Defintion. If the query ends with a ?, a nilable representation of the reolved type definition is returned.
@return [Type::Definition]
# File lib/type.rb, line 17 def find(query) return query if query.kind_of?(Definition) query = String(query) nilable = query.end_with?('?') && query.slice!(-1) definition = const_get(query) (nilable ? definition.nilable : definition) end
Also aliased as: []
register(definition)
click to toggle source
@api private @param [Type::Definition] @return [void]
# File lib/type.rb, line 31 def register(definition) if (name = definition.name) const_set(name, definition) (class << self; self; end).instance_exec do define_method("#{name}!") { |x| definition.cast!(x) } define_method("#{name}?") { |x| definition.valid?(x) } end end end
scalar(name = nil, &block)
click to toggle source
@see Definition::Scalar#generate
# File lib/type/definition/scalar.rb, line 6 def scalar(name = nil, &block) Definition::Scalar.generate(name, &block) end