Class: Dry::Validation::Rust::Schema::FieldDefinition Private
- Inherits:
-
Object
- Object
- Dry::Validation::Rust::Schema::FieldDefinition
- Defined in:
- lib/dry/validation/rust/schema/field_definition.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
- #children ⇒ Object private
- #filled ⇒ Object private
- #member ⇒ Object private
- #name ⇒ Object private
- #nullable ⇒ Object private
- #predicates ⇒ Object readonly private
- #required ⇒ Object private
- #ruby_type ⇒ Object private
- #type ⇒ Object private
Instance Method Summary collapse
- #add_predicate(name, argument: true) ⇒ Object private
- #child_at(name) ⇒ Object private
- #deep_dup ⇒ Object private
-
#initialize(name:, required:) ⇒ FieldDefinition
constructor
private
A new instance of FieldDefinition.
- #normalized_type ⇒ Object private
- #to_native_h ⇒ Object private
Constructor Details
#initialize(name:, required:) ⇒ FieldDefinition
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 FieldDefinition.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/dry/validation/rust/schema/field_definition.rb', line 12 def initialize(name:, required:) @name = name&.to_sym @required = required @nullable = false @filled = false @type = :any @member = nil @ruby_type = nil @children = [] @children_by_name = {} @predicates = [] end |
Instance Attribute Details
#children ⇒ 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.
10 11 12 |
# File 'lib/dry/validation/rust/schema/field_definition.rb', line 10 def children @children end |
#filled ⇒ 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.
9 10 11 |
# File 'lib/dry/validation/rust/schema/field_definition.rb', line 9 def filled @filled end |
#member ⇒ 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.
9 10 11 |
# File 'lib/dry/validation/rust/schema/field_definition.rb', line 9 def member @member end |
#name ⇒ 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.
9 10 11 |
# File 'lib/dry/validation/rust/schema/field_definition.rb', line 9 def name @name end |
#nullable ⇒ 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.
9 10 11 |
# File 'lib/dry/validation/rust/schema/field_definition.rb', line 9 def nullable @nullable end |
#predicates ⇒ 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.
10 11 12 |
# File 'lib/dry/validation/rust/schema/field_definition.rb', line 10 def predicates @predicates end |
#required ⇒ 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.
9 10 11 |
# File 'lib/dry/validation/rust/schema/field_definition.rb', line 9 def required @required end |
#ruby_type ⇒ 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.
9 10 11 |
# File 'lib/dry/validation/rust/schema/field_definition.rb', line 9 def ruby_type @ruby_type end |
#type ⇒ 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.
9 10 11 |
# File 'lib/dry/validation/rust/schema/field_definition.rb', line 9 def type @type end |
Instance Method Details
#add_predicate(name, argument: true) ⇒ 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 42 |
# File 'lib/dry/validation/rust/schema/field_definition.rb', line 34 def add_predicate(name, argument: true) normalized_name = name.to_s.delete_suffix('?').to_sym unless (NATIVE_PREDICATES | RUBY_PREDICATES).include?(normalized_name) raise UnsupportedFeatureError, "predicate #{normalized_name.inspect} is not supported natively; move it to a contract rule" end predicates << Predicate.new(name: normalized_name, argument: argument) end |
#child_at(name) ⇒ 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.
30 31 32 |
# File 'lib/dry/validation/rust/schema/field_definition.rb', line 30 def child_at(name) @children_by_name[name.to_sym] end |
#deep_dup ⇒ 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.
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/dry/validation/rust/schema/field_definition.rb', line 65 def deep_dup self.class.new(name: name, required: required).tap do |copy| copy.nullable = nullable copy.filled = filled copy.type = type copy.ruby_type = ruby_type copy.member = member&.deep_dup copy.children = children.map(&:deep_dup) predicates.each do |predicate| copy.predicates << predicate.with(argument: duplicate_value(predicate.argument)) end end end |
#normalized_type ⇒ 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.
61 62 63 |
# File 'lib/dry/validation/rust/schema/field_definition.rb', line 61 def normalized_type type == :datetime ? :date_time : type end |
#to_native_h ⇒ 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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/dry/validation/rust/schema/field_definition.rb', line 44 def to_native_h { name: name&.to_s, required: required, nullable: nullable, filled: filled, type: normalized_type.to_s, member: member&.to_native_h, children: children.map(&:to_native_h), predicates: predicates.filter_map do |predicate| next unless NATIVE_PREDICATES.include?(predicate.name) { name: predicate.name.to_s, argument: predicate.argument } end } end |