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)

  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) click to toggle source

@api private

# File lib/dry/schema/macros/filled.rb, line 29
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 50
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 40
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 45
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 55
def schema_type
  schema_dsl.types[name]
end