Sha256: 5b28e6a9b433030f6c2fafdcc14cd077751a25146744b7ca0e1f7c5c2ea18d46

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

Contents

module Solve
  module Tracers
    class << self
      # @param [#say] ui
      #
      # @returns [AbstractTracer]
      def build(ui)
        unless ui.respond_to?(:say)
          Solve::Tracers::Silent.new
        else
          Solve::Tracers::HumanReadable.new(ui)
        end
      end
    end

    class AbstractTracer
      class << self
        private

          def must_define(*args)
            args.each do |method|
              define_method(method.to_sym) do |*args|
                raise AbstractFunction, "##{method} must be defined on #{self.class}"
              end
            end
          end
      end

      TRACER_METHODS = [
        :start,
        :searching_for,
        :add_constraint,
        :possible_values,
        :trying,
        :backtrack,
        :cannot_backtrack,
        :solution,
        :reset_domain,
        :unbind,
        :remove_variable,
        :remove_constraint,
      ]

      must_define *TRACER_METHODS
    end
  end
end

require_relative 'tracers/human_readable'
require_relative 'tracers/silent'

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
solve-0.8.2 lib/solve/tracers.rb
solve-0.8.1 lib/solve/tracers.rb
solve-0.8.0 lib/solve/tracers.rb