Class: Dry::Types::Implication

Inherits:
Object
  • Object
show all
Includes:
Composition
Defined in:
lib/dry/types/implication.rb

Overview

Implication type

Instance Attribute Summary

Attributes included from Composition

#left, #right

Attributes included from Options

#options

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Composition

#constrained?, #default?, #failure, included, #initialize, #name, #optional?, #success, #to_ast, #to_proc

Methods included from Printable

#to_s

Methods included from Meta

#initialize, #meta, #pristine, #with

Methods included from Options

#initialize, #with

Methods included from Builder

#&, #>, #constrained, #constrained_type, #constructor, #constructor_type, #default, #enum, #fallback, #lax, #maybe, #optional, #|

Methods included from Type

#call, #valid?

Class Method Details

.operatorObject



11
12
13
# File 'lib/dry/types/implication.rb', line 11

def self.operator
  :>
end

Instance Method Details

#call_safe(input, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • input (Object)

Returns:

  • (Object)


33
34
35
36
37
38
39
# File 'lib/dry/types/implication.rb', line 33

def call_safe(input, &block)
  if left.try(input).success?
    right.call_safe(input, &block)
  else
    input
  end
end

#call_unsafe(input) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • input (Object)

Returns:

  • (Object)


20
21
22
23
24
25
26
# File 'lib/dry/types/implication.rb', line 20

def call_unsafe(input)
  if left.try(input).success?
    right.call_unsafe(input)
  else
    input
  end
end

#primitive?(value) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • value (Object)

Returns:

  • (Boolean)


57
58
59
60
61
62
63
# File 'lib/dry/types/implication.rb', line 57

def primitive?(value)
  if left.primitive?(value)
    right.primitive?(value)
  else
    true
  end
end

#try(input) ⇒ Object

Parameters:

  • input (Object)


44
45
46
47
48
49
50
# File 'lib/dry/types/implication.rb', line 44

def try(input)
  if left.try(input).success?
    right.try(input)
  else
    Result::Success.new(input)
  end
end