Class: Dry::Types::Definition::Array

Inherits:
Dry::Types::Definition show all
Defined in:
lib/dry/types/definition/array.rb

Instance Attribute Summary

Attributes inherited from Dry::Types::Definition

#options, #primitive

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Dry::Types::Definition

[], #call, #initialize, #name, #try, #valid?, #with

Methods included from Builder

#constrained, #constructor, #default, #enum, #optional, #safe, #|

Constructor Details

This class inherits a constructor from Dry::Types::Definition

Class Method Details

.constructor(member_constructor, array) ⇒ Object



5
6
7
# File 'lib/dry/types/definition/array.rb', line 5

def self.constructor(member_constructor, array)
  array.map { |value| member_constructor[value] }
end

Instance Method Details

#member(type) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/dry/types/definition/array.rb', line 9

def member(type)
  member_constructor =
    case type
    when String, Class then Types[type]
    else type
    end

  array_constructor = self.class
    .method(:constructor).to_proc.curry.(member_constructor)

  constructor(array_constructor, member: member_constructor)
end