Class: Farce::Internal::DryTypes::CollectionType

Inherits:
Object
  • Object
show all
Includes:
Dry::Types::Builder, Dry::Types::Type
Defined in:
lib/farce/integrations/dry_types.rb

Overview

A regular dry type that constructs a Farce value.

Direct Known Subclasses

AtomType, MapType, SequenceType

Dry Types Integration collapse

Dry Types Integration collapse

Instance Attribute Details

#source ⇒ Dry::Types::Type (readonly)

The dry type evaluated before Farce construction.

Returns:

  • (Dry::Types::Type) —

    The source type.



144
145
146
# File 'lib/farce/integrations/dry_types.rb', line 144

def source
  @source
end

Instance Method Details

#call(input = ::Dry::Types::Undefined) {|partial| ... } ⇒ Object? Also known as: []

Apply validation, coercion, and Farce construction to input.

Parameters:

  • input (Object) (defaults to: ::Dry::Types::Undefined) —

    The input value.

Yields:

  • (partial) —

    Handle a coercion or construction failure.

Yield Parameters:

  • partial (Object) —

    The partial value supplied by dry-types.

Yield Returns:

  • (Object) —

    The fallback returned instead of a Farce value.

Returns:

  • (Object, nil) —

    The Farce value, nil for an optional type, or the failure block result.



176
# File 'lib/farce/integrations/dry_types.rb', line 176

def call(input = ::Dry::Types::Undefined, &) = @type.call(input, &)

#constrained? ⇒ Boolean

Report whether this type contains constraints.

Returns:

  • (Boolean) —

    Whether constraints are present.



233
# File 'lib/farce/integrations/dry_types.rb', line 233

def constrained? = @type.constrained?

#default? ⇒ Boolean

Report whether this is a default type.

Returns:

  • (Boolean) —

    Whether a default is configured.



229
# File 'lib/farce/integrations/dry_types.rb', line 229

def default? = @type.default?

#inspect ⇒ String

Return the wrapped dry type representation.

Returns:

  • (String) —

    The printable type representation.



263
# File 'lib/farce/integrations/dry_types.rb', line 263

def inspect = @type.inspect

#meta ⇒ Hash #meta(data) ⇒ CollectionType

Read or extend this type's metadata.

Overloads:

  • #meta ⇒ Hash

    Returns The current metadata.

    Returns:

    • (Hash) —

      The current metadata.

  • #meta(data) ⇒ CollectionType

    Returns A collection type carrying the metadata.

    Parameters:

    • data (Hash) —

      Metadata to merge into the source type.

    Returns:



276
277
278
279
280
# File 'lib/farce/integrations/dry_types.rb', line 276

def meta(data = ::Dry::Types::Undefined)
  return @type.meta if ::Dry::Types::Undefined.equal?(data)

  self.class.new(source.meta(data), kind:, configuration:)
end

#name ⇒ String

Return the output type name.

Returns:

  • (String) —

    The Farce class or optional union name.



225
# File 'lib/farce/integrations/dry_types.rb', line 225

def name = @type.name

#optional? ⇒ Boolean

Report whether this type accepts nil.

Returns:

  • (Boolean) —

    Whether the type is optional.



237
# File 'lib/farce/integrations/dry_types.rb', line 237

def optional? = @type.optional?

#primitive?(input) ⇒ Boolean

Test whether a value is accepted by the output type.

Parameters:

  • input (Object) —

    The value to test.

Returns:

  • (Boolean) —

    Whether the value is a configured Farce object or accepted nil.



216
# File 'lib/farce/integrations/dry_types.rb', line 216

def primitive?(input) = @type.primitive?(input)

#pristine ⇒ CollectionType

Return a new type without source metadata.

Returns:



284
# File 'lib/farce/integrations/dry_types.rb', line 284

def pristine = self.class.new(source.pristine, kind:, configuration:)

#to_ast(meta: true) ⇒ Array

Return the dry-types abstract syntax tree.

Parameters:

  • meta (Boolean) (defaults to: true) —

    Whether metadata is included.

Returns:

  • (Array) —

    The type AST.



255
# File 'lib/farce/integrations/dry_types.rb', line 255

def to_ast(meta: true) = @type.to_ast(meta:)

#to_proc ⇒ Proc

Convert this type to a callable object.

Returns:

  • (Proc) —

    A proc that applies the type.



259
# File 'lib/farce/integrations/dry_types.rb', line 259

def to_proc = proc { call(it) }

#try(input) {|failure| ... } ⇒ Dry::Types::Result, Object

Try to construct a Farce value and return a dry-types result.

Parameters:

  • input (Object) —

    The value to process.

Yields:

  • (failure) —

    Handle a failed attempt.

Yield Parameters:

  • failure (Dry::Types::Result::Failure) —

    The failure result.

Yield Returns:

  • (Object) —

    The fallback result.

Returns:

  • (Dry::Types::Result, Object) —

    The result or failure block value.



200
# File 'lib/farce/integrations/dry_types.rb', line 200

def try(input, &) = @type.try(input, &)

#valid?(input = ::Dry::Types::Undefined) ⇒ Boolean Also known as: ===

Test whether input can produce a valid Farce value.

Parameters:

  • input (Object) (defaults to: ::Dry::Types::Undefined) —

    The value to test.

Returns:

  • (Boolean) —

    Whether applying the type succeeds.



205
# File 'lib/farce/integrations/dry_types.rb', line 205

def valid?(input = ::Dry::Types::Undefined) = @type.valid?(input)

#with(mode: UNDEFINED, scope: UNDEFINED, **source_options) ⇒ CollectionType

Return a new Farce type with different output or source options.

Parameters:

  • mode (Symbol) (defaults to: UNDEFINED) —

    The transfer mode for the shared variant.

  • scope (Symbol) (defaults to: UNDEFINED) —

    The storage scope for the local variant.

  • source_options (Hash) —

    Options forwarded to the source dry type.

Returns:

Raises:

  • (ArgumentError) —

    If the Farce type does not support the requested output option.



292
293
294
295
296
# File 'lib/farce/integrations/dry_types.rb', line 292

def with(mode: UNDEFINED, scope: UNDEFINED, **source_options)
  configured = configuration.with(kind:, mode:, scope:)
  next_source = source_options.empty? ? source : source.with(**source_options)
  self.class.new(next_source, kind:, configuration: configured)
end