Module: FinchAPI::Type::Union Private
- Includes:
- Converter
- Included in:
- Models::HRIS::DocumentRetreiveResponse, Models::WebhookEvent
- Defined in:
- lib/finch-api/type/union.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Instance Method Summary collapse
- #==(other) ⇒ Boolean private
- #===(other) ⇒ Boolean private
- #coerce(value, state:) ⇒ Object private
- #dump(value) ⇒ Object private
-
#variants ⇒ Array<Object>
private
All of the specified variants for this union.
Methods included from Converter
Instance Method Details
#==(other) ⇒ 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.
122 123 124 |
# File 'lib/finch-api/type/union.rb', line 122 def ==(other) other.is_a?(Module) && other.singleton_class <= FinchAPI::Union && other.derefed_variants == derefed_variants end |
#===(other) ⇒ 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.
113 114 115 116 117 |
# File 'lib/finch-api/type/union.rb', line 113 def ===(other) known_variants.any? do |_, variant_fn| variant_fn.call === other end end |
#coerce(value, state:) ⇒ 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.
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/finch-api/type/union.rb', line 139 def coerce(value, state:) if (target = resolve_variant(value)) return FinchAPI::Type::Converter.coerce(target, value, state: state) end strictness = state.fetch(:strictness) exactness = state.fetch(:exactness) state[:strictness] = strictness == :strong ? true : strictness alternatives = [] known_variants.each do |_, variant_fn| target = variant_fn.call exact = state[:exactness] = {yes: 0, no: 0, maybe: 0} state[:branched] += 1 coerced = FinchAPI::Type::Converter.coerce(target, value, state: state) yes, no, maybe = exact.values if (no + maybe).zero? || (!strictness && yes.positive?) exact.each { exactness[_1] += _2 } state[:exactness] = exactness return coerced elsif maybe.positive? alternatives << [[-yes, -maybe, no], exact, coerced] end end case alternatives.sort_by(&:first) in [] exactness[:no] += 1 if strictness == :strong = "no possible conversion of #{value.class} into a variant of #{target.inspect}" raise ArgumentError.new() end value in [[_, exact, coerced], *] exact.each { exactness[_1] += _2 } coerced end .tap { state[:exactness] = exactness } ensure state[:strictness] = strictness end |
#dump(value) ⇒ 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.
187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/finch-api/type/union.rb', line 187 def dump(value) if (target = resolve_variant(value)) return FinchAPI::Type::Converter.dump(target, value) end known_variants.each do target = _2.call return FinchAPI::Type::Converter.dump(target, value) if target === value end super end |
#variants ⇒ Array<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.
All of the specified variants for this union.
47 |
# File 'lib/finch-api/type/union.rb', line 47 def variants = derefed_variants.map(&:last) |