Sha256: 3555a0acf2f052b39f2c8cf4cb6e9b234aa7607a6f2d4c0151c64b871fd25153

Contents?: true

Size: 1.05 KB

Versions: 3

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module Rake
  module Funnel
    class AmbiguousFileError < StandardError
      attr_reader :task_name, :search_pattern, :candidates, :description

      def initialize(message, task_name, search_pattern, candidates)
        description = "Could not run task '#{task_name}'. #{message}"
        super(description)

        @description = description
        @task_name = task_name
        @search_pattern = search_pattern
        @candidates = candidates
      end

      def to_s
        msg = [] << inspect_description << inspect_search_pattern << inspect_candidates
        msg = msg.flatten.compact
        msg = [super.to_s] if msg.empty?

        msg.join("\n")
      end

      private

      def inspect_description
        [description] if description
      end

      def inspect_search_pattern
        ["Search pattern used: #{search_pattern}"] if search_pattern
      end

      def inspect_candidates
        return if (candidates || []).empty?

        ['Candidates:', candidates.map { |c| "  - #{c}" }]
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rake-funnel-0.24.0 lib/rake/funnel/ambiguous_file_error.rb
rake-funnel-0.23.0 lib/rake/funnel/ambiguous_file_error.rb
rake-funnel-0.22.3 lib/rake/funnel/ambiguous_file_error.rb