Sha256: 4e725a5f7ce45c74732d0dee54dac7cad9582c084b3f9240442468dec70680d2

Contents?: true

Size: 1.21 KB

Versions: 7

Compression:

Stored size: 1.21 KB

Contents

require 'active_support/inflector'

module Leap
  # Raised when a Leap solution cannot be found. 
  #
  # If this is raised unexpectedly, try removing compliance constraints or double-checking that you have enough quorums within mainline committees to provide conclusions given any combination of input data.
  class NoSolutionError < ArgumentError;
    # Create the excpetion
    def initialize(options = {})
      @goal = options[:goal]
      @deliberation = options[:deliberation]
      
      if @goal
        help = "No solution was found for \"#{@goal}\"."
      else
        help = "No solution was found."
      end
      
      if @deliberation
        help << " (#{deliberation_report})"
      end
      
      super help
    end
    
    private
    
    # A report on the deliberation proceedings, for debugging purposes.
    def deliberation_report
      @deliberation.characteristics.keys.sort_by(&:to_s).map do |characteristic|
        statement = "#{characteristic}: "
        if report = @deliberation.reports.find { |r| r.committee.name == characteristic }
          statement << report.quorum.name.humanize.downcase
        else
          statement << 'provided as input'
        end
      end.join ', '
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
leap-0.5.6 lib/leap/no_solution_error.rb
leap-0.5.5 lib/leap/no_solution_error.rb
leap-0.5.4 lib/leap/no_solution_error.rb
leap-0.5.3 lib/leap/no_solution_error.rb
leap-0.5.2 lib/leap/no_solution_error.rb
leap-0.5.1 lib/leap/no_solution_error.rb
leap-0.5.0 lib/leap/no_solution_error.rb