Module: FinchAPI::Union Private
- Includes:
- Converter
- Included in:
- Models::HRIS::DocumentRetreiveResponse, Models::WebhookEvent
- Defined in:
- lib/finch-api/base_model.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.
521 522 523 |
# File 'lib/finch-api/base_model.rb', line 521 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.
512 513 514 515 516 |
# File 'lib/finch-api/base_model.rb', line 512 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.
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 |
# File 'lib/finch-api/base_model.rb', line 538 def coerce(value, state:) if (target = resolve_variant(value)) return FinchAPI::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::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.
586 587 588 589 590 591 592 593 594 595 596 597 |
# File 'lib/finch-api/base_model.rb', line 586 def dump(value) if (target = resolve_variant(value)) return FinchAPI::Converter.dump(target, value) end known_variants.each do target = _2.call return FinchAPI::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.
446 |
# File 'lib/finch-api/base_model.rb', line 446 def variants = derefed_variants.map(&:last) |