Module: Dry::Types::BuilderMethods
- Defined in:
- lib/dry/types/builder_methods.rb
Instance Method Summary collapse
-
#Array(type) ⇒ Dry::Types::Array
Build an array type.
-
#Constant(object) ⇒ Dry::Types::Type
Build a type with a single value The equality check done with
equal?. -
#Constructor(klass, cons = nil, &block) ⇒ Dry::Types::Type
Build a constructor type If no constructor block given it uses .new method.
-
#Definition(klass) ⇒ Dry::Types::Type
Build a definiton type.
-
#Hash(schema, type_map) ⇒ Dry::Types::Array
Build a hash schema.
- #included(base) ⇒ Object private
-
#Instance(klass) ⇒ Dry::Types::Type
Build a type which values are instances of a given class Values are checked using
is_a?call. -
#Value(value) ⇒ Dry::Types::Type
Build a type with a single value The equality check done with
eql?.
Instance Method Details
#Array(type) ⇒ Dry::Types::Array
Build an array type. It is a shortcut for Array.of
19 20 21 |
# File 'lib/dry/types/builder_methods.rb', line 19 def Array(type) self::Array.of(type) end |
#Constant(object) ⇒ Dry::Types::Type
Build a type with a single value
The equality check done with equal?
63 64 65 |
# File 'lib/dry/types/builder_methods.rb', line 63 def Constant(object) Definition.new(object.class).constrained(is: object) end |
#Constructor(klass, cons = nil, &block) ⇒ Dry::Types::Type
Build a constructor type If no constructor block given it uses .new method
76 77 78 |
# File 'lib/dry/types/builder_methods.rb', line 76 def Constructor(klass, cons = nil, &block) Definition.new(klass).constructor(cons || block || klass.method(:new)) end |
#Definition(klass) ⇒ Dry::Types::Type
Build a definiton type
86 87 88 |
# File 'lib/dry/types/builder_methods.rb', line 86 def Definition(klass) Definition.new(klass) end |
#Hash(schema, type_map) ⇒ Dry::Types::Array
Build a hash schema
30 31 32 |
# File 'lib/dry/types/builder_methods.rb', line 30 def Hash(schema, type_map) self::Hash.public_send(schema, type_map) end |
#included(base) ⇒ Object
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.
5 6 7 8 |
# File 'lib/dry/types/builder_methods.rb', line 5 def included(base) super base.extend(BuilderMethods) end |
#Instance(klass) ⇒ Dry::Types::Type
Build a type which values are instances of a given class
Values are checked using is_a? call
41 42 43 |
# File 'lib/dry/types/builder_methods.rb', line 41 def Instance(klass) Definition.new(klass).constrained(type: klass) end |
#Value(value) ⇒ Dry::Types::Type
Build a type with a single value
The equality check done with eql?
52 53 54 |
# File 'lib/dry/types/builder_methods.rb', line 52 def Value(value) Definition.new(value.class).constrained(eql: value) end |