Class: Dry::Types::Array::Member
- Inherits:
-
Dry::Types::Array
- Object
- Definition
- Dry::Types::Array
- Dry::Types::Array::Member
- Defined in:
- lib/dry/types/array/member.rb
Instance Attribute Summary collapse
-
#member ⇒ Object
readonly
Returns the value of attribute member.
Attributes inherited from Definition
Attributes included from Options
Instance Method Summary collapse
- #call(input, meth = :call) ⇒ Object (also: #[])
-
#initialize(primitive, options = {}) ⇒ Member
constructor
A new instance of Member.
- #try(input, &block) ⇒ Object
- #valid?(type) ⇒ Boolean
Methods inherited from Definition
[], #constrained?, #default?, #failure, #name, #primitive?, #result, #success
Methods included from Builder
#constrained, #constrained_type, #constructor, #default, #enum, #maybe, #optional, #safe, #|
Methods included from Options
Constructor Details
#initialize(primitive, options = {}) ⇒ Member
Returns a new instance of Member.
7 8 9 10 |
# File 'lib/dry/types/array/member.rb', line 7 def initialize(primitive, = {}) @member = .fetch(:member) super end |
Instance Attribute Details
#member ⇒ Object (readonly)
Returns the value of attribute member.
5 6 7 |
# File 'lib/dry/types/array/member.rb', line 5 def member @member end |
Instance Method Details
#call(input, meth = :call) ⇒ Object Also known as: []
12 13 14 |
# File 'lib/dry/types/array/member.rb', line 12 def call(input, meth = :call) input.map { |el| member.__send__(meth, el) } end |
#try(input, &block) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/dry/types/array/member.rb', line 21 def try(input, &block) if input.is_a?(::Array) result = call(input, :try) output = result.map(&:input) if result.all?(&:success?) success(output) else failure = failure(output, result.select(&:failure?)) block ? yield(failure) : failure end else failure = failure(input, "#{input} is not an array") block ? yield(failure) : failure end end |
#valid?(type) ⇒ Boolean
17 18 19 |
# File 'lib/dry/types/array/member.rb', line 17 def valid?(type) super && type.all? { |el| member.valid?(el) } end |