Sha256: 2e1bc0e25c934258f25b7e80f451b47c6a0a94257b481ff575c50c9398420c20

Contents?: true

Size: 836 Bytes

Versions: 48

Compression:

Stored size: 836 Bytes

Contents

# frozen_string_literal: true

class Tramway::Error < RuntimeError
  def initialize(*args, plugin: nil, method: nil, message: nil)
    @properties = {}
    @properties[:plugin] = plugin
    @properties[:method] = method
    @properties[:message] = message
    super(*args)
  end

  def message
    "Plugin: #{@properties[:plugin]}; Method: #{@properties[:method]}; Message: #{@properties[:message]}"
  end

  def properties
    @properties ||= {}
  end

  class << self
    def raise_error(*coordinates, **options)
      @errors ||= YAML.load_file("#{Tramway::Core.root}/yaml/errors.yml").with_indifferent_access
      error = @errors.dig(*coordinates)
      raise 'Error is not defined in YAML' unless error

      options.each do |pair|
        error.gsub!("%{#{pair[0]}}", pair[1].to_s)
      end
      raise error
    end
  end
end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
tramway-core-2.0.2.2 lib/tramway/error.rb
tramway-core-2.0.2.1 lib/tramway/error.rb
tramway-core-2.0.2 lib/tramway/error.rb
tramway-core-2.0.1.2 lib/tramway/error.rb
tramway-core-2.0.1.1 lib/tramway/error.rb
tramway-core-2.0.1 lib/tramway/error.rb
tramway-core-2.0.0.8 lib/tramway/error.rb
tramway-core-2.0.0.7 lib/tramway/error.rb
tramway-core-2.0.0.6 lib/tramway/error.rb
tramway-core-2.0.0.5 lib/tramway/error.rb
tramway-core-2.0.0.4 lib/tramway/error.rb
tramway-core-2.0.0.3 lib/tramway/error.rb
tramway-core-2.0.0.2 lib/tramway/error.rb
tramway-core-2.0.0.1 lib/tramway/error.rb
tramway-core-2.0 lib/tramway/error.rb
tramway-core-1.18.6.1 lib/tramway/error.rb
tramway-core-1.18.6 lib/tramway/error.rb
tramway-core-1.18.5.2 lib/tramway/error.rb
tramway-core-1.18.5.1 lib/tramway/error.rb
tramway-core-1.18.5 lib/tramway/error.rb