Class: Dry::Schema::Macros::Filled Private

Inherits:
Value show all
Defined in:
lib/dry/schema/macros/filled.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 prepend ‘:filled?` predicate

Instance Attribute Summary

Attributes inherited from DSL

#chain, #predicate_inferrer, #primitive_inferrer

Instance Method Summary collapse

Methods inherited from Value

#array_type?, #build_array_type, #hash_type?, #import_steps, #maybe_type?, #respond_to_missing?

Methods inherited from DSL

#array, #custom_type?, #each, #filled, #hash, #maybe, #schema, #type, #value

Methods inherited from Core

#new, #operation, #path, #to_ast, #to_rule

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Dry::Schema::Macros::Value

Instance Method Details

#call(*predicates, **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.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dry/schema/macros/filled.rb', line 11

def call(*predicates, **opts, &block)
  ensure_valid_predicates(predicates)

  append_macro(Macros::Value) do |macro|
    if opts[:type_spec] && !filter_empty_string?
      macro.call(predicates[0], :filled?, *predicates[1..predicates.size - 1], **opts,
                 &block)
    elsif opts[:type_rule]
      macro.call(:filled?).value(*predicates, **opts, &block)
    else
      macro.call(:filled?, *predicates, **opts, &block)
    end
  end
end

#ensure_valid_predicates(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.



27
28
29
30
31
32
33
34
35
# File 'lib/dry/schema/macros/filled.rb', line 27

def ensure_valid_predicates(predicates)
  if predicates.include?(:empty?)
    raise ::Dry::Schema::InvalidSchemaError, "Using filled with empty? predicate is invalid"
  end

  if predicates.include?(:filled?)
    raise ::Dry::Schema::InvalidSchemaError, "Using filled with filled? is redundant"
  end
end

#expected_primitivesObject

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.



48
49
50
# File 'lib/dry/schema/macros/filled.rb', line 48

def expected_primitives
  primitive_inferrer[schema_type]
end

#filter_empty_string?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.

Returns:

  • (Boolean)


38
39
40
# File 'lib/dry/schema/macros/filled.rb', line 38

def filter_empty_string?
  !expected_primitives.include?(NilClass) && processor_config.filter_empty_string
end

#processor_configObject

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
# File 'lib/dry/schema/macros/filled.rb', line 43

def processor_config
  schema_dsl.processor_type.config
end

#schema_typeObject

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.



53
54
55
# File 'lib/dry/schema/macros/filled.rb', line 53

def schema_type
  schema_dsl.types[name]
end