Sha256: 34d7512c5d5cf051cab34dd92d8cd4dc7af70764c1fdcf610371b0c9e8d012b1

Contents?: true

Size: 1.89 KB

Versions: 1

Compression:

Stored size: 1.89 KB

Contents

module Fontist
  module Errors
    class GeneralError < StandardError; end

    class BinaryCallError < GeneralError; end
    class FontIndexCorrupted < GeneralError; end
    class FontNotFoundError < GeneralError; end
    class FormulaIndexNotFoundError < GeneralError; end
    class InvalidResourceError < GeneralError; end
    class LicensingError < GeneralError; end
    class ManifestCouldNotBeFoundError < GeneralError; end
    class ManifestCouldNotBeReadError < GeneralError; end
    class MissingAttributeError < GeneralError; end
    class TamperedFileError < GeneralError; end
    class TimeoutError < GeneralError; end
    class UnknownFontTypeError < GeneralError; end

    class FontError < GeneralError
      attr_reader :font, :style

      def initialize(msg, font = nil, style = nil)
        @font = font
        @style = style

        super(msg)
      end

      def name
        messages = []
        messages << "Font name: '#{@font}'"
        messages << "Style: '#{@style}'" if @style
        messages.join("; ")
      end
    end

    class MissingFontError < FontError
      def initialize(font, style = nil)
        name = prepare_name(font, style)
        msg = "#{name} font is missing, please run `fontist install '#{font}'` to download the font."

        super(msg, font, style)
      end

      private

      def prepare_name(font, style)
        names = []
        names << "'#{font}'"
        names << "'#{style}'" if style
        names.join(" ")
      end
    end

    class UnsupportedFontError < FontError
      def initialize(font)
        msg = <<~MSG.chomp
          Font '#{font}' not found locally nor available in the Fontist formula repository.
          Perhaps it is available at the latest Fontist formula repository.
          You can update the formula repository using the command `fontist update` and try again.
        MSG

        super(msg, font)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fontist-1.8.3 lib/fontist/errors.rb