Module: Dry::Types::Composition
Defined Under Namespace
Modules: Constrained
Instance Attribute Summary collapse
Attributes included from Options
#options
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Printable
#to_s
Methods included from Meta
#meta, #pristine, #with
Methods included from Options
#with
Methods included from Builder
#&, #>, #constrained, #constrained_type, #constructor, #constructor_type, #default, #enum, #fallback, #lax, #maybe, #optional, #|
Methods included from Type
#call, #valid?
Instance Attribute Details
22
23
24
|
# File 'lib/dry/types/composition.rb', line 22
def left
@left
end
|
#right ⇒ Type
25
26
27
|
# File 'lib/dry/types/composition.rb', line 25
def right
@right
end
|
Class Method Details
.included(base) ⇒ Object
37
38
39
40
41
42
43
|
# File 'lib/dry/types/composition.rb', line 37
def self.included(base)
composition_name = Inflector.demodulize(base)
ast_type = Inflector.underscore(composition_name).to_sym
base.define_singleton_method(:ast_type) { ast_type }
base.define_singleton_method(:composition_name) { composition_name }
base.const_set("Constrained", ::Class.new(base) { include Constrained })
end
|
Instance Method Details
#call_safe(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.
88
|
# File 'lib/dry/types/composition.rb', line 88
def call_safe(input, &) = raise ::NotImplementedError
|
#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.
81
|
# File 'lib/dry/types/composition.rb', line 81
def call_unsafe(input) = raise ::NotImplementedError
|
#constrained? ⇒ false
69
|
# File 'lib/dry/types/composition.rb', line 69
def constrained? = false
|
#default? ⇒ false
64
|
# File 'lib/dry/types/composition.rb', line 64
def default? = false
|
#failure(input, _error = nil) ⇒ 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.
106
107
108
109
110
111
112
113
|
# File 'lib/dry/types/composition.rb', line 106
def failure(input, _error = nil)
result = try(input)
if result.failure?
result
else
raise ::ArgumentError, "Invalid failure value '#{input}' for #{inspect}"
end
end
|
#initialize(left, right, **options) ⇒ 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.
50
51
52
53
54
|
# File 'lib/dry/types/composition.rb', line 50
def initialize(left, right, **options)
super
@left, @right = left, right
freeze
end
|
#name ⇒ String
59
|
# File 'lib/dry/types/composition.rb', line 59
def name = "#{left.name} #{self.class.operator} #{right.name}"
|
#optional? ⇒ Boolean
74
|
# File 'lib/dry/types/composition.rb', line 74
def optional? = false
|
#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.
120
|
# File 'lib/dry/types/composition.rb', line 120
def primitive?(value) = raise ::NotImplementedError
|
#success(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.
96
97
98
99
100
101
102
103
|
# File 'lib/dry/types/composition.rb', line 96
def success(input)
result = try(input)
if result.success?
result
else
raise ::ArgumentError, "Invalid success value '#{input}' for #{inspect}"
end
end
|
#to_ast(meta: true) ⇒ Object
125
126
127
128
|
# File 'lib/dry/types/composition.rb', line 125
def to_ast(meta: true)
[self.class.ast_type,
[left.to_ast(meta: meta), right.to_ast(meta: meta), meta ? self.meta : EMPTY_HASH]]
end
|
#to_proc ⇒ Proc
Wrap the type with a proc
135
|
# File 'lib/dry/types/composition.rb', line 135
def to_proc = proc { |value| self.(value) }
|
#try(input) ⇒ Object
93
|
# File 'lib/dry/types/composition.rb', line 93
def try(input, &) = raise ::NotImplementedError
|