Class: Dry::Schema::Macros::Array Private
- Defined in:
- lib/dry/schema/macros/array.rb
Overview
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.
Macro used to specify predicates for each element of an array
Instance Attribute Summary
Attributes inherited from DSL
#chain, #predicate_inferrer, #primitive_inferrer
Instance Method Summary collapse
- #to_ast ⇒ Object (also: #ast) private
-
#value(*args, **opts, &block) ⇒ Object
private
rubocop: disable Metrics/PerceivedComplexity rubocop: disable Metrics/AbcSize.
Methods inherited from DSL
#array, #custom_type?, #each, #filled, #hash, #maybe, #schema, #type
Methods inherited from Core
#new, #operation, #path, #to_rule
Instance Method Details
#to_ast ⇒ Object Also known as: ast
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.
47 48 49 |
# File 'lib/dry/schema/macros/array.rb', line 47 def to_ast(*) [:and, [trace.array?.to_ast, [:each, trace.to_ast]]] end |
#value(*args, **opts, &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.
rubocop: disable Metrics/PerceivedComplexity rubocop: disable Metrics/AbcSize
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/dry/schema/macros/array.rb', line 13 def value(*args, **opts, &block) type(:array) extract_type_spec(args, set_type: false) do |*predicates, type_spec:, type_rule:| type(schema_dsl.array[type_spec]) if type_spec is_hash_block = type_spec.equal?(:hash) if predicates.any? || opts.any? || !is_hash_block super( *predicates, type_spec: type_spec, type_rule: type_rule, **opts, &(is_hash_block ? nil : block) ) end is_op = args.size.equal?(2) && args[1].is_a?(Logic::Operations::Abstract) if is_hash_block && !is_op hash(&block) elsif is_op hash = Value.new(schema_dsl: schema_dsl.new, name: name).hash(args[1]) trace.captures.concat(hash.trace.captures) type(schema_dsl.types[name].of(hash.schema_dsl.types[name])) end end self end |