Module: Type
- Defined in:
- lib/type.rb,
lib/type/error.rb,
lib/type/version.rb,
lib/type/definition.rb,
lib/type/builtin/scalar.rb,
lib/type/definition/proxy.rb,
lib/type/definition/scalar.rb,
lib/type/builtin/collection.rb,
lib/type/definition/nilable.rb,
lib/type/definition/collection.rb,
lib/type/definition/collection/constrained.rb
Overview
The built-in collection types are defined here.
Defined Under Namespace
Modules: Definition Classes: CastError, Error, ValidationError
Constant Summary collapse
- VERSION =
The Type gem is semantically versioned.
'0.2.0'
Class Method Summary collapse
-
.collection(name = nil, &block) ⇒ Object
see Definition::Collection#generate.
- .find(query) ⇒ Type::Definition (also: [])
- .register(definition) ⇒ void private
- .scalar(name = nil, &block) ⇒ Object
Class Method Details
.collection(name = nil, &block) ⇒ Object
see Definition::Collection#generate
8 9 10 |
# File 'lib/type/definition/collection.rb', line 8 def collection(name = nil, &block) Definition::Collection.generate(name, &block) end |
.find(query) ⇒ Type::Definition .find(query) ⇒ Type::Definition Also known as: []
17 18 19 20 21 22 23 24 25 |
# 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 |
.register(definition) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
31 32 33 34 35 36 37 38 39 |
# 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) ⇒ Object
6 7 8 |
# File 'lib/type/definition/scalar.rb', line 6 def scalar(name = nil, &block) Definition::Scalar.generate(name, &block) end |