Class: Dry::Validation::Rust::Schema::FieldBuilder Private
- Inherits:
-
Object
- Object
- Dry::Validation::Rust::Schema::FieldBuilder
- Defined in:
- lib/dry/validation/rust/schema/field_builder.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
- #definition ⇒ Object readonly private
- #mode ⇒ Object readonly private
Instance Method Summary collapse
- #array(member_type = nil, **predicates, &block) ⇒ Object private
- #each(member_type = nil, **predicates) ⇒ Object private
- #filled(*specs, **predicates) ⇒ Object private
- #hash(schema = nil, &block) ⇒ Object private
-
#initialize(definition, mode:) ⇒ FieldBuilder
constructor
private
A new instance of FieldBuilder.
- #maybe(*specs, **predicates) ⇒ Object private
- #method_missing(name, *args, **kwargs, &block) ⇒ Object private
- #respond_to_missing?(name, include_private = false) ⇒ Boolean private
- #value(*specs, **predicates, &block) ⇒ Object private
Constructor Details
#initialize(definition, mode:) ⇒ FieldBuilder
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 FieldBuilder.
11 12 13 14 |
# File 'lib/dry/validation/rust/schema/field_builder.rb', line 11 def initialize(definition, mode:) @definition = definition @mode = mode end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, **kwargs, &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.
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/dry/validation/rust/schema/field_builder.rb', line 75 def method_missing(name, *args, **kwargs, &block) if name.to_s.end_with?('?') && block.nil? argument = if kwargs.empty? args.length <= 1 ? args.first : args else kwargs end definition.add_predicate(name, argument: argument.nil? || argument) return self end super end |
Instance Attribute Details
#definition ⇒ Object (readonly)
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.
9 10 11 |
# File 'lib/dry/validation/rust/schema/field_builder.rb', line 9 def definition @definition end |
#mode ⇒ Object (readonly)
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.
9 10 11 |
# File 'lib/dry/validation/rust/schema/field_builder.rb', line 9 def mode @mode end |
Instance Method Details
#array(member_type = nil, **predicates, &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.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/dry/validation/rust/schema/field_builder.rb', line 43 def array(member_type = nil, **predicates, &block) definition.type = :array predicates.each { |name, argument| definition.add_predicate(name, argument: argument) } if member_type member = FieldDefinition.new(name: nil, required: true) if member_type.is_a?(Schema) member.type = :hash member.children = member_type.fields.map(&:deep_dup) elsif custom_type?(member_type) raise UnsupportedFeatureError, 'custom dry-types array members are not supported by the Ruby fallback yet' else assign_type(member, member_type) end definition.member = member end if block definition.member ||= FieldDefinition.new(name: nil, required: true) definition.member.type = :hash nested = DSL.new(mode: mode) nested.instance_eval(&block) definition.member.children = nested.fields end self end |
#each(member_type = nil, **predicates) ⇒ 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.
71 72 73 |
# File 'lib/dry/validation/rust/schema/field_builder.rb', line 71 def each(member_type = nil, **predicates, &) array(member_type, **predicates, &) end |
#filled(*specs, **predicates) ⇒ 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.
24 25 26 27 |
# File 'lib/dry/validation/rust/schema/field_builder.rb', line 24 def filled(*specs, **predicates, &) definition.filled = true value(*specs, **predicates, &) end |
#hash(schema = nil, &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.
34 35 36 37 38 39 40 41 |
# File 'lib/dry/validation/rust/schema/field_builder.rb', line 34 def hash(schema = nil, &block) definition.type = :hash nested = DSL.new(mode: mode) nested.import(schema) if schema nested.instance_eval(&block) if block definition.children = nested.fields self end |
#maybe(*specs, **predicates) ⇒ 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.
29 30 31 32 |
# File 'lib/dry/validation/rust/schema/field_builder.rb', line 29 def maybe(*specs, **predicates, &) definition.nullable = true value(*specs, **predicates, &) end |
#respond_to_missing?(name, include_private = false) ⇒ Boolean
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.
89 90 91 |
# File 'lib/dry/validation/rust/schema/field_builder.rb', line 89 def respond_to_missing?(name, include_private = false) name.to_s.end_with?('?') || super end |
#value(*specs, **predicates, &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.
16 17 18 19 20 21 22 |
# File 'lib/dry/validation/rust/schema/field_builder.rb', line 16 def value(*specs, **predicates, &block) apply_specs(specs, predicates) if block nested_value_block? ? nested_target(block) : PredicateBlock.new(definition).instance_eval(&block) end self end |