module Factree::Pathfinder

@api private

Public Class Methods

find(raw_facts, &decide) click to toggle source

@see DSL.find_path

# File lib/factree/pathfinder.rb, line 8
def self.find(raw_facts, &decide)
  facts_without_spy = Factree::Facts.coerce(raw_facts)
  required_facts = []
  facts = Factree::FactsSpy.new(facts_without_spy) do |*fact_names|
    required_facts += fact_names
  end

  conclusion = Factree::Facts.catch_missing_facts do
    conclusion = decide.call(facts)
    type_check_conclusion conclusion, &decide
    conclusion
  end

  Factree::Path.new(required_facts.uniq, conclusion)
end

Private Class Methods

type_check_conclusion(conclusion, &decide) click to toggle source
# File lib/factree/pathfinder.rb, line 24
                     def self.type_check_conclusion(conclusion, &decide)
  unless conclusion.is_a? Factree::Conclusion
    raise Factree::InvalidConclusionError,
      "Expected #{decide.inspect} to return a Factree::Conclusion. " +
      "Got #{conclusion.inspect}"
  end
end