Class: Dry::Types::Schema::Key Private
- Inherits:
-
Object
- Object
- Dry::Types::Schema::Key
- Defined in:
- lib/dry/types/schema/key.rb,
lib/dry/types/extensions/maybe.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Attribute Summary collapse
- #name ⇒ Symbol readonly
- #options ⇒ Hash included from Options readonly private
- #type ⇒ Type included from Decorator readonly
Instance Method Summary collapse
-
#&(other) ⇒ Intersection, Intersection::Constrained
included
from Builder
private
Compose two types into an Intersection type.
-
#>(other) ⇒ Implication, Implication::Constrained
included
from Builder
private
Compose two types into an Implication type.
-
#call(input = Undefined, &block) ⇒ Object
(also: #[])
included
from Type
Apply type to a value.
- #call_safe(input, &block) ⇒ Object private
- #call_unsafe(input) ⇒ Object private
-
#constrained(options) ⇒ Constrained
included
from Builder
Turn a type into a constrained type.
- #constrained? ⇒ Boolean included from Decorator
- #constrained_type ⇒ Class included from Builder private
-
#constructor(constructor = nil, **options, &block) ⇒ Constructor
(also: #append, #prepend, #>>, #<<)
included
from Builder
Define a constructor for the type.
- #constructor_type ⇒ Class included from Builder private
-
#default(input = Undefined, options = EMPTY_HASH, &block) ⇒ Default
included
from Builder
Turn a type into a type with a default value.
- #default? ⇒ Boolean included from Decorator
-
#enum(*values) ⇒ Enum
included
from Builder
Define an enum on top of the existing type.
-
#fallback(value = Undefined, shared: false, &_fallback) ⇒ Constructor
included
from Builder
Use the given value on type mismatch.
-
#initialize(type, name, required: Undefined, **options) ⇒ Key
constructor
private
A new instance of Key.
-
#lax ⇒ Lax
Turn key into a lax type.
- #maybe ⇒ Object private
- #meta(data = Undefined) ⇒ Object
-
#omittable ⇒ Dry::Types::Schema::Key
Make key not required.
-
#optional ⇒ Key
Make wrapped type optional.
-
#required(required = Undefined) ⇒ Object
Control whether the key is required.
-
#required? ⇒ Boolean
Whether the key is required in schema input.
- #respond_to_missing?(meth, include_private = false) ⇒ Boolean included from Decorator
-
#to_ast(meta: true) ⇒ Array
Dump to internal AST representation.
-
#to_proc ⇒ Proc
included
from Decorator
Wrap the type with a proc.
- #to_s ⇒ String (also: #inspect) included from Printable private
- #try(input, &block) ⇒ Object
-
#valid?(input = Undefined) ⇒ Boolean
(also: #===)
included
from Type
private
Whether a value is a valid member of the type.
- #with(**new_options) ⇒ Type included from Options private
-
#|(other) ⇒ Sum, Sum::Constrained
included
from Builder
private
Compose two types into a Sum type.
Constructor Details
#initialize(type, name, required: Undefined, **options) ⇒ Key
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.
Returns a new instance of Key.
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/dry/types/schema/key.rb', line 26 def initialize(type, name, required: Undefined, **) required = Undefined.default(required) do type..fetch(:required) { !type..fetch(:omittable, false) } end unless name.is_a?(::Symbol) raise ArgumentError, "Schemas can only contain symbol keys, #{name.inspect} given" end super(type, name, required: required, **) @name = name end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Dry::Types::Decorator
Instance Attribute Details
#name ⇒ Symbol (readonly)
23 24 25 |
# File 'lib/dry/types/schema/key.rb', line 23 def name @name end |
Instance Method Details
#&(other) ⇒ Intersection, Intersection::Constrained Originally defined in module Builder
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.
Compose two types into an Intersection type
#>(other) ⇒ Implication, Implication::Constrained Originally defined in module Builder
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.
Compose two types into an Implication type
#call(input = Undefined) ⇒ Object #call(input = Undefined) {|output| ... } ⇒ Object Also known as: [] Originally defined in module Type
Apply type to a value
#call_safe(input, &block) ⇒ 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.
40 41 42 |
# File 'lib/dry/types/schema/key.rb', line 40 def call_safe(input, &block) type.call_safe(input, &block) end |
#call_unsafe(input) ⇒ 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.
45 46 47 |
# File 'lib/dry/types/schema/key.rb', line 45 def call_unsafe(input) type.call_unsafe(input) end |
#constrained(options) ⇒ Constrained Originally defined in module Builder
Turn a type into a constrained type
#constrained? ⇒ Boolean Originally defined in module Decorator
#constrained_type ⇒ Class Originally defined in module Builder
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.
#constructor(constructor = nil, **options, &block) ⇒ Constructor Also known as: append, prepend, >>, << Originally defined in module Builder
Define a constructor for the type
#constructor_type ⇒ Class Originally defined in module Builder
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.
#default(input = Undefined, options = EMPTY_HASH, &block) ⇒ Default Originally defined in module Builder
Turn a type into a type with a default value
#default? ⇒ Boolean Originally defined in module Decorator
#enum(*values) ⇒ Enum Originally defined in module Builder
Define an enum on top of the existing type
#fallback(value = Undefined, shared: false, &_fallback) ⇒ Constructor Originally defined in module Builder
Use the given value on type mismatch
#lax ⇒ Lax
Turn key into a lax type. Lax types are not strict hence such keys are not required
99 100 101 |
# File 'lib/dry/types/schema/key.rb', line 99 def lax __new__(type.lax).required(false) end |
#maybe ⇒ 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.
107 108 109 |
# File 'lib/dry/types/extensions/maybe.rb', line 107 def maybe __new__(type.maybe) end |
#meta(data = Undefined) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/dry/types/schema/key.rb', line 131 def (data = Undefined) if Undefined.equal?(data) || !data.key?(:omittable) super else self.class.warn( "Using meta for making schema keys is deprecated, " \ "please use .omittable or .required(false) instead" \ "\n" + Core::Deprecations::STACK.() ) super.required(!data[:omittable]) end end |
#omittable ⇒ Dry::Types::Schema::Key
Make key not required
90 91 92 |
# File 'lib/dry/types/schema/key.rb', line 90 def omittable required(false) end |
#optional ⇒ Key
Make wrapped type optional
108 109 110 |
# File 'lib/dry/types/schema/key.rb', line 108 def optional __new__(type.optional) end |
#required ⇒ Boolean #required(required) ⇒ Dry::Types::Schema::Key
Control whether the key is required
77 78 79 80 81 82 83 |
# File 'lib/dry/types/schema/key.rb', line 77 def required(required = Undefined) if Undefined.equal?(required) .fetch(:required) else with(required: required) end end |
#required? ⇒ Boolean
Whether the key is required in schema input
61 62 63 |
# File 'lib/dry/types/schema/key.rb', line 61 def required? .fetch(:required) end |
#respond_to_missing?(meth, include_private = false) ⇒ Boolean Originally defined in module Decorator
#to_ast(meta: true) ⇒ Array
Dump to internal AST representation
117 118 119 120 121 122 123 124 125 126 |
# File 'lib/dry/types/schema/key.rb', line 117 def to_ast(meta: true) [ :key, [ name, required, type.to_ast(meta: ) ] ] end |
#to_proc ⇒ Proc Originally defined in module Decorator
Wrap the type with a proc
#to_s ⇒ String Also known as: inspect Originally defined in module Printable
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.
#try(input, &block) ⇒ Object
52 53 54 |
# File 'lib/dry/types/schema/key.rb', line 52 def try(input, &block) type.try(input, &block) end |
#valid?(input = Undefined) ⇒ Boolean Also known as: === Originally defined in module Type
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.
Whether a value is a valid member of the type
#with(**new_options) ⇒ Type Originally defined in module Options
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.
#|(other) ⇒ Sum, Sum::Constrained Originally defined in module Builder
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.
Compose two types into a Sum type