Module: FinchAPI::Internal::Type::Union Private
- Includes:
- Converter, Util::SorbetRuntimeSupport
- Included in:
- Models::HRIS::DocumentRetreiveResponse, Models::HRIS::EmploymentData, Models::HRIS::EmploymentData::UnionMember0::CustomField::Value, Models::HRIS::Individual, Models::WebhookEvent
- Defined in:
- lib/finch_api/internal/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
- #===(other) ⇒ Boolean
- #coerce(value, state:) ⇒ Object private
- #dump(value, state:) ⇒ Object private
- #hash ⇒ Integer
- #inspect(depth: 0) ⇒ String private
-
#variants ⇒ Array<Object>
private
All of the specified variants for this union.
Methods included from Util::SorbetRuntimeSupport
#const_missing, #define_sorbet_constant!
Methods included from Converter
coerce, dump, inspect, type_info
Instance Method Details
#==(other) ⇒ Boolean
128 129 130 |
# File 'lib/finch_api/internal/type/union.rb', line 128 def ==(other) FinchAPI::Internal::Type::Union === other && other.derefed_variants == derefed_variants end |
#===(other) ⇒ Boolean
117 118 119 120 121 |
# File 'lib/finch_api/internal/type/union.rb', line 117 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.
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 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/finch_api/internal/type/union.rb', line 150 def coerce(value, state:) if (target = resolve_variant(value)) return FinchAPI::Internal::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::Internal::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, 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.
202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/finch_api/internal/type/union.rb', line 202 def dump(value, state:) if (target = resolve_variant(value)) return FinchAPI::Internal::Type::Converter.dump(target, value, state: state) end known_variants.each do target = _2.call return FinchAPI::Internal::Type::Converter.dump(target, value, state: state) if target === value end super end |
#hash ⇒ Integer
135 |
# File 'lib/finch_api/internal/type/union.rb', line 135 def hash = variants.hash |
#inspect(depth: 0) ⇒ String
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.
223 224 225 226 227 228 229 230 231 232 |
# File 'lib/finch_api/internal/type/union.rb', line 223 def inspect(depth: 0) if depth.positive? return is_a?(Module) ? super() : self.class.name end members = variants.map { FinchAPI::Internal::Type::Converter.inspect(_1, depth: depth.succ) } prefix = is_a?(Module) ? name : self.class.name "#{prefix}[#{members.join(' | ')}]" 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.
49 |
# File 'lib/finch_api/internal/type/union.rb', line 49 def variants = derefed_variants.map(&:last) |