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
Attributes included from Decorator
Attributes included from Options
Instance Method Summary collapse
- #call_safe(input) ⇒ Object private
- #call_unsafe(input) ⇒ Object private
-
#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.
-
#to_ast(meta: true) ⇒ Array
Dump to internal AST representation.
- #try(input) ⇒ Object
Methods included from Printable
Methods included from Builder
#&, #>, #constrained, #constrained_type, #constructor, #constructor_type, #default, #enum, #fallback, #|
Methods included from Decorator
#constrained?, #default?, #respond_to_missing?, #to_proc
Methods included from Options
Methods included from 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 38 |
# 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 @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
#call_safe(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.
41 |
# File 'lib/dry/types/schema/key.rb', line 41 def call_safe(input, &) = type.call_safe(input, &) |
#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.
44 |
# File 'lib/dry/types/schema/key.rb', line 44 def call_unsafe(input) = type.call_unsafe(input) |
#lax ⇒ Lax
Turn key into a lax type. Lax types are not strict hence such keys are not required
90 |
# File 'lib/dry/types/schema/key.rb', line 90 def lax = __new__(type.lax).required(false) |
#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.
103 |
# File 'lib/dry/types/extensions/maybe.rb', line 103 def maybe = __new__(type.maybe) |
#meta(data = Undefined) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/dry/types/schema/key.rb', line 118 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
83 |
# File 'lib/dry/types/schema/key.rb', line 83 def omittable = required(false) |
#optional ⇒ Key
Make wrapped type optional
97 |
# File 'lib/dry/types/schema/key.rb', line 97 def optional = __new__(type.optional) |
#required ⇒ Boolean #required(required) ⇒ Dry::Types::Schema::Key
Control whether the key is required
70 71 72 73 74 75 76 |
# File 'lib/dry/types/schema/key.rb', line 70 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
56 |
# File 'lib/dry/types/schema/key.rb', line 56 def required? = .fetch(:required) |
#to_ast(meta: true) ⇒ Array
Dump to internal AST representation
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/dry/types/schema/key.rb', line 104 def to_ast(meta: true) [ :key, [ name, required, type.to_ast(meta: ) ] ] end |
#try(input) ⇒ Object
49 |
# File 'lib/dry/types/schema/key.rb', line 49 def try(input, &) = type.try(input, &) |