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 collapse

Attributes inherited from DSL

#chain, #predicate_inferrer

Instance Method Summary collapse

Methods inherited from Value

#respond_to_missing?

Methods inherited from DSL

#array, #each, #filled, #hash, #schema, #type, #value

Methods inherited from Core

#new, #operation, #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 Attribute Details

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

PrimitiveInferrer used to get a list of primitive classes from configured type

Returns:



17
# File 'lib/dry/schema/macros/filled.rb', line 17

option :primitive_inferrer, default: proc { PrimitiveInferrer.new }

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.



20
21
22
23
24
25
26
27
28
# File 'lib/dry/schema/macros/filled.rb', line 20

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

  if opts[:type_spec] && !filter_empty_string?
    value(predicates[0], :filled?, *predicates[1..predicates.size - 1], **opts, &block)
  else
    value(:filled?, *predicates, **opts, &block)
  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.

rubocop:disable Style/GuardClause



32
33
34
35
36
37
38
39
40
# File 'lib/dry/schema/macros/filled.rb', line 32

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.



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

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)


44
45
46
# File 'lib/dry/schema/macros/filled.rb', line 44

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.



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

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.



59
60
61
# File 'lib/dry/schema/macros/filled.rb', line 59

def schema_type
  schema_dsl.types[name]
end