Sha256: 5a56ac6f66305e2d43fc35825f7903bcc26ed8f7bf3723d0aeebeee64af371d6

Contents?: true

Size: 1.05 KB

Versions: 11

Compression:

Stored size: 1.05 KB

Contents

require 'yaml'

module Vagrant
  module Util
    # This class is responsible for outputting errors. It retrieves the errors,
    # based on their key, from the error file, and then outputs it.
    class Errors
      @@errors = nil

      class <<self
        # Resets the internal errors hash to nil, forcing a reload on the next
        # access of {errors}.
        def reset!
          @@errors = nil
        end

        # Returns the hash of errors from the error YML files. This only loads once,
        # then returns a cached value until {reset!} is called.
        #
        # @return [Hash]
        def errors
          @@errors ||= YAML.load_file(File.join(PROJECT_ROOT, "templates", "errors.yml"))
        end

        # Renders the error with the given key and data parameters and returns
        # the rendered result.
        #
        # @return [String]
        def error_string(key, data = {})
          template = errors[key] || "Unknown error key: #{key}"
          TemplateRenderer.render_string(template, data)
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 3 rubygems

Version Path
vagrantup-0.3.4 lib/vagrant/util/errors.rb
vagrantup-0.3.3 lib/vagrant/util/errors.rb
vagrantup-0.3.2 lib/vagrant/util/errors.rb
vagrantup-0.3.1 lib/vagrant/util/errors.rb
vagrantup-0.3.0 lib/vagrant/util/errors.rb
vagrant-0.3.4 lib/vagrant/util/errors.rb
vagrant-0.3.3 lib/vagrant/util/errors.rb
vagrant-0.3.2 lib/vagrant/util/errors.rb
vagrant-0.3.1 lib/vagrant/util/errors.rb
vagrant-0.3.0 lib/vagrant/util/errors.rb
bmabey-vagrant-0.2.0 lib/vagrant/util/errors.rb