class Dry::Schema::Macros::Filled

Macro used to prepend `:filled?` predicate

@api private

Public Instance Methods

call(*predicates, **opts, &block) click to toggle source

@api private

# File lib/dry/schema/macros/filled.rb, line 13
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)
  elsif opts[:type_rule]
    value(:filled?).value(*predicates, **opts, &block)
  else
    value(:filled?, *predicates, **opts, &block)
  end
end
ensure_valid_predicates(predicates) click to toggle source

@api private

# File lib/dry/schema/macros/filled.rb, line 26
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_primitives() click to toggle source

@api private

# File lib/dry/schema/macros/filled.rb, line 47
def expected_primitives
  primitive_inferrer[schema_type]
end
filter_empty_string?() click to toggle source

@api private

# File lib/dry/schema/macros/filled.rb, line 37
def filter_empty_string?
  !expected_primitives.include?(NilClass) && processor_config.filter_empty_string
end
processor_config() click to toggle source

@api private

# File lib/dry/schema/macros/filled.rb, line 42
def processor_config
  schema_dsl.processor_type.config
end
schema_type() click to toggle source

@api private

# File lib/dry/schema/macros/filled.rb, line 52
def schema_type
  schema_dsl.types[name]
end